首页 > 代码库 > 2015年NEUACM一月月赛 C
2015年NEUACM一月月赛 C
问题 C: Sum?Sum!
时间限制: 1 Sec 内存限制: 128 MB提交: 653 解决: 176
[提交][状态][讨论版]
题目描述
Kid want to learn math better.Now Kid know how to calculate the sum of 1 to n in a short time.But this time,he is given a much more difficult question——to calculate the sum of 1 to 10^n.Kid think for a long time——10^10 ms and then he solve the question successfully.
Do you know how to solve it ?
输入
The first line is a integer t(1<=t<=10),indicate the number of case.
For each t,there is a integer n(the meaning of n is in the above),0<=n<=10^4.
输出
For each case,just print the answer of the sum.
样例输入
11
样例输出
55
提示
思路:其实这是由规律的n=1的时候是55,n=2的时候5050,n=3 500500,n=4 50005000。。。。一直下去
PS注意n=0事为1
#include <iostream>#include <cstdio>using namespace std;int main(){ int t,n,i; scanf("%d",&t); while(t--) { scanf("%d",&n); if(n==0) { printf("1\n"); continue; } printf("5"); for(i=0; i<n-1; i++) { printf("0"); } printf("5"); for(i=0; i<n-1; i++) { printf("0"); } printf("\n"); } return 0;}
2015年NEUACM一月月赛 C
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。