2-06. Sum of series (20) (zjupat mathematics)

Source: Internet
Author: User

Link: http://pat.zju.edu.cn/contests/ds/2-06


Given a number a (1 <= A <= 9) and a non-negative integer N (0 <= n <= 100000), calculate the sum of the series S = a + AA + AAA +... + AA... A (n ). For example, if a = 1, n = 3, S = 1 + 11 + 111 = 123.

Input format description:

Enter the number a and the non-negative integer n.

Output format description:

Output the value of S in the sum of n columns.

Sample input and output:

Serial number Input Output
1
1 3
123
2
6 100
7407407407407407407407407407407407407407407407407407407407407407407407407407407407407407407407407340
3
1 0
0


The Code is as follows:

#include <cstdio>#include <cmath>int a[100017];int main(){    int A, N;    while(~scanf("%d%d",&A,&N))    {        if(N == 0)        {            printf("0\n");            continue;        }        int tt = 0,p = 0;        int j = 0;        for(int i = N; i >= 1; i--)        {            tt = A*i+p;            p = tt/10;            a[j++] = tt%10;        }        if(p > 0)        {            a[j++] =  p;        }        for(int i = j-1; i >= 0; i--)        {            printf("%d",a[i]);        }        printf("\n");    }    return 0;}


2-06. Sum of series (20) (zjupat mathematics)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.