UVa 913 - Joana and the Odd Numbers
来源:互联网 发布:清空数据库sql语句 编辑:程序博客网 时间:2024/06/06 03:26
题目:将奇数按照1,3,5,...的个数按顺序写成三角形。问有n个数字那行,最后的三个数字之和。
分析:数学题。n对应的为 n = 2*k-1,的第k行。k = (n+1)/ 2
根据奇数和公式,可知第k行结束的数字为第k*k个奇数。
即 2k*k-1 = (n+1)/ 2 ,所以最后三个数字和为 2*k*k-1 + 2*k*k-3 + 2*k*k-5 = 6*k*k-9
说明:要用long long类型,防止溢出。
#include <iostream>#include <cstdlib>using namespace std;int main(){long long n;while ( cin >> n ) cout << ((n+1)/2*(n+1)/2)*6-9 << endl;return 0;}
0 0
- UVa 913 - Joana and the Odd Numbers
- Algorithm: Make all the odd numbers precede all the even numbers in an array.
- uva 11481 Arrange the Numbers
- UVa:11481 Arrange the Numbers
- UVA - 11481 Arrange the Numbers
- UVa 10712 - Count the Numbers
- UVa 12683 Odd and Even Zeroes(数论+数位DP)
- non-zero winding number rule and the even-odd rule
- UVa 10783 - Odd Sum
- UVA 10783 - Odd Sum
- UVa 10783-Odd Sum
- UVA 10712 - Count the Numbers (数位DP)
- uva 11481 - Arrange the Numbers(计数问题)
- uva 10712 - Count the Numbers(数位dp)
- UVA 11481 Arrange the Numbers (容斥)
- UVA 10712 - Count the Numbers 容斥
- Sum All Odd Fibonacci Numbers
- Sum All Odd Fibonacci Numbers
- USACO zerosum DFS 1A
- 程序员生存定律--成长路上常见的坑
- 二叉堆维护优先队列
- gcc编译(学习object c)
- c/c++学习_字符串处理
- UVa 913 - Joana and the Odd Numbers
- [转载]常用牛人主页链接(计算机视觉、模式识别、机器学习相关方向,陆续更新。。。。)
- VirtualProtect 3方法 -seh ret-ASLR-dep-Adrenalin Player 2.2.5.3
- as3中点击按钮或者输入文本框后舞台无法接收键盘输入的解决方法
- 编写访问数据库的应用层程序,经常catch出的一些错误
- 一句话动态开辟二维数组
- 【PhoneGAP学习】Android PhoneGap框架(1)--重要知识点的预先学习(XHR)
- 1039. Course List for Student
- 游戏服务器之线程池调度策略