Bob is a world-renowned stick collector. His most prized stick possessions include:
• an Arctic Redwood branch from a hike near Dawson City,
• a Desert Pine stick from a visit to the Grand Canyon, and
• a Chinese Arbour twig from an adventure into Tibet.
    Bob collects sticks in a peculiar way. He will only accept a new stick into his collection if its length is exactly length n + 1 cm where n is the number of sticks currently in his collection. This implies his collection of n sticks contains exactly one stick of length 1 cm through n cm.
    One day Alice visited Bob to inspect his stick collection (upon Bob’s insistence of course). Alice wasn’t particularly interested in Bob’s excessive descriptions and needed a quick conversation changer. Cleverly, she posed the following question to Bob: “If you are allowed to take any 3 sticks from your collection, how many different triangles can you make?”
    Can you help Bob answer the question so he can get back to telling Alice about his sticks?
Input
The input will begin with t (1 ≤ t ≤ 1000), the number of test cases. Each test case will contain an integer n (3 ≤ n ≤ 1000000), the number of sticks in Bob’s collection. (Recall if Bob has n sticks, then he has exactly one stick of each of the lengths from 1 cm through n cm.)
Output
For each test case, output on a line the number of different triangles you can make with Bob’s sticks. Triangles X and Y are different if there is at least one stick in X that is not in Y . A triangle has area strictly greater than 0.
Sample Input
3
3
4
10
Sample Output
0
1
50

问题链接:UVA11554 Hapless Hedonism
问题简述:(略)
问题分析:数学计算中的大数问题。经过推导得fx=(x-2)*(x-2)/4,gx=0(x=1,2,3),gx=gx-1+fx(x>3)。需要用到128位整数计算。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11554 Hapless Hedonism */#include <bits/stdc++.h>using namespace std;typedef __int128 INT128;
const int N = 1000000;
INT128 g[N + 1];void printi128(INT128 n)
{if (n < 0) {putchar('-'); printi128(-n);}else if (n < 10) {putchar(n % 10 + '0');}else {printi128(n / 10); putchar(n % 10 + '0');}
}int main()
{g[0] = g[1] = g[2] = g[3] = 0;for (INT128 i = 4; i <= N; i++)g[i] = g[i - 1] + (i - 2) * (i - 2) / 4;int t, n;scanf("%d", &t);while (t--) {scanf("%d", &n);printi128(g[n]);putchar('\n');}return 0;
}

AC的C++语言程序如下:

/* UVA11554 Hapless Hedonism */#include <bits/stdc++.h>using namespace std;int main()
{int t;scanf("%d", &t);while (t--) {int n;unsigned long long ans = 0;scanf("%d", &n);for (int i = 1; i <= n; i++) {double p = n - (i + i + 1);if (p > 0) ans += (unsigned long long)(p * (p + 1)) / 2;}printf("%lld\n", ans);}return 0;
}

UVA11554 Hapless Hedonism【数学计算+大数】相关推荐

  1. PHP运算口诀,超级实用的数学计算知识顺口溜

    超级实用的数学计算知识顺口溜: 一.20以内进位加法 看大数,分小数,凑整十,加零头. (掌握"凑十法",提倡"递推法".) 二.20以内退位减法 20以内退位 ...

  2. js函数语法:ASCII 码的相互转换,字符串操作,数学计算

    ASCII 码的相互转换 for (let i = 'a'.charCodeAt(); i <= 'z'.charCodeAt(); i++) {a.push(String.fromCharCo ...

  3. P4588 [TJOI2018]数学计算(线段树维护区间乘和单点修改)

    P4588 [TJOI2018]数学计算 刚看到这题根本每想到用线段树,直接每次记录计算结果然后找到要除的数字就好了呗 但是!你会注意到,如果连续乘很多很多次,然后再除的话,如果不取模会爆 long ...

  4. MATLAB数学计算与工程分析范例教程,MATLAB数学计算与工程分析范例教程

    基本信息 书名:MATLAB数学计算与工程分析范例教程 定价:28.00元 作者:石博强,赵金 编著 出版社:中国铁道出版社 出版日期:2005-05-01 ISBN:9787#113057596 字 ...

  5. Shell脚本笔记(三)shell中的数学计算

    shell中的数学计算 一.使用方括号 #!/bin/bash a=10 b=29 c=88res=$[$a * ($c-$b)] echo $res 二.使用(()) echo $((1+9)) ( ...

  6. python数值运算答案_笨方法学Python 习题3:数字和数学计算

    数字和数学计算 print("I will now count my chickens") print("Hens",25+30/6) print(" ...

  7. 用计算机计算的手抄报内容,关于数学计算手抄报

    开办手抄报对学生是一项综合性很强的实践活动.下面是学习啦小编为大家带来的关于数学计算手抄报,希望大家喜欢. 数学计算手抄报的图片欣赏 数学计算手抄报图一 数学计算手抄报图二 数学计算手抄报图三 数学计 ...

  8. php+数学计算公式,PHP数学计算函数总结

    PHP数学计算函数总结 发布于 2015-01-21 16:53:26 | 189 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertext Preproc ...

  9. 《“笨办法”学Python(第3版)》——习题3 数字和数学计算

    本节书摘来自异步社区<"笨办法"学Python(第3版)>一书中的习题3,作者[美]Zed A. Shaw,王巍巍 译,更多章节内容可以访问云栖社区"异步社区 ...

最新文章

  1. UVA11400 照明系统设计 Lighting System Design(线性DP)
  2. 静态路由实验配置举例
  3. 【渝粤题库】陕西师范大学200411 数学建模 作业(专升本)
  4. java的empty_Java Stack empty()方法与示例
  5. MDOP 2011 R2 DaRT 7.0 创建包含诊断和恢复的图形化PE
  6. 【MATLAB基础】——函数的使用
  7. arcgis api for js共享干货系列之二自定义Navigation控件样式风格
  8. 2.4 理解指数加权平均
  9. JavaScript学习笔记(六)
  10. 公文排版字体要求以及印制要求
  11. 使用R语言的spgwr包进行地理加权回归(GWR)
  12. 文科生学大数据分析吃力吗
  13. # 写论文也要告别abandon模式
  14. 蓝桥杯复数运算python
  15. (Android-RTC-1)Android-WebRTC初体验
  16. 辨别亦真亦假的Svchost.exe
  17. PBO(Pixel Buffer Object),将像素数据存储在显存中
  18. 单极性霍尔开关OH3144/OH44E
  19. 【总结】职业规划和自我总结----------包含职业要求
  20. 传输线的物理基础(三):传输线的瞬时阻抗

热门文章

  1. vscode配置python2和python3_VS Code中配置python版本以及Python多版本
  2. 给 QtCtreator 工程文件 pro 配置 pthread库和liburcu库
  3. GDAL中MEM格式的简单使用示例
  4. java工具类使用逗号切割字符串_【java】分割字符串工具类,霸气 jdk自带的
  5. 中级工程师考试2019——地图制图与地理信息系统
  6. Kubeadm installation
  7. C#注册类方法到Lua
  8. Phonegap VS AppCan
  9. 来自reallh大的游戏编程饕餮大餐!
  10. 如何将html转为report,如何把Html5 Report Viewer添加到Web项目