PTA 7-38 数列求和-加强版

https://pintia.cn/problem-sets/14/problems/3006
large numbers, 大数加法
特判要写return 0; 别让他做剩下的操作

#include 
#include 
#include 
#include 
#include 
typedef long long ll;
using namespace std;

int ar[1000000];

int main() {
    int A, N;
    scanf("%d%d", &A, &N);

    if (N == 0) {
        printf("0\n");
        return 0;//之前这里忘了写return 0;
    }

    ll left = 0, v;
    int cnt = 0;
    for (int i = 0; i < N || left > 0; i++) {
        v = (N - i) * A + left;
        ar[i] = v % 10;
        left = v / 10;
        cnt++;
        //printf("%lld %lld %d   ", v, left, ar[i]);
    }
//  printf("\n");
    for (int i = 0; i < cnt; i++) {
        printf("%d", ar[cnt - i - 1]);
    }
    printf("\n");
    return 0;
}

你可能感兴趣的:(PTA 7-38 数列求和-加强版)