问题 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.

 

样例输入

1
1

样例输出

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;
}

 

posted on 2015-01-31 18:22  Wing丶编程菜鸟  阅读(186)  评论(0编辑  收藏  举报