SGU - 123 - The sum (简单数学!)
来源:互联网 发布:淘宝数字油画 编辑:程序博客网 时间:2024/05/18 02:00
SGU - 123
The sum
Time Limit: 250MS Memory Limit: 4096KB 64bit IO Format: %I64d & %I64u
Description
Here is your second problem, keep calm and solve it .
Nacci sequence of numbers is known to all : F1 = 1; F2 = 1; Fn+1 = Fn + Fn-1, for n>1. You have to find S - the sum of the first K Nacci numbers.
Input
First line contains natural number K (0<K<41).
Output
First line should contain number S.
Sample Input
5
Sample Output
12
Source
简单数学求和题,,居然int都不会爆,,刚开始我还以为要long long。。
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define LL long longusing namespace std;int a[42] = {0,1,1};int main(){int k;for(int i=3; i<41; i++){a[i] = a[i-1] + a[i-2];}scanf("%d", &k);int ans = 0;for(int i=1; i<=k; i++){ans += a[i];}printf("%d\n", ans);return 0;}
1 0
- SGU - 123 - The sum (简单数学!)
- sgu 123 The sum
- sgu 123 The sum
- SGU 123 The sum(水~)
- [SGU]123. The sum
- Sgu 123. The sum
- SGU - 107 - 987654321 problem (简单数学!)
- SGU - 135 - Drawing Lines (简单数学!)
- hdoj the Sum of Cube 5053 (简单数学)
- SGU 123. The sum 无敌水题
- POJ 1844 Sum【简单数学】
- HDOJ 2058 The sum problem(数学问题)
- HDOJ 题目2058The sum problem(数学)
- hdu 2058 The sum problem (数学问题)
- HDOJ 2058 The sum problem(数学求和问题)
- HDOJ-2058(The sum problem)(找规律)(数学)
- SGU 231 Prime Sum(傻逼题)
- HDU 2058 The sum problem [数学]
- xcode运行模拟器时出现问题 (Domain = FBSOpenApplicationErrorDomain, Code = 4)
- Python http访问学习
- c++字符串详解
- keepalived仅实现HA
- HDU_2665 Kth number[可持续化线段树]
- SGU - 123 - The sum (简单数学!)
- R语言绘制箱线图
- linux网络编程之socket(十三):epoll 系列函数简介、与select、poll 的区别
- php面向对象_get(),_set()的用法
- NSFileManager操作2
- Gradle构建项目小技巧
- ceph存储 ceph-fuse源码分析一
- MysqlExplain详解
- Javase基础学习笔记之集合(1)