跳到正文

个人记录

【四月份 -- 基础语法组】-- T2--求和(sum.cpp)

zhangyuqiTAT约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年4月12日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 1 分钟

版本

  1. v1当前

题解: https://b1bznc26af6.feishu.cn/file/JtRHbyrOcoOg3Gx5ftxcyKBJnPe?from=from_copylink

网址: https://cspjs.online/contest/680/problem/2

C++
#include<bits/stdc++.h>
using namespace std;
int sum[2000100],a[2000010];
int colo(int x){
    int ret=0;
    while(x!=0){
        ret+=x%10;
        x/=10;
    }
    return ret;
}
int main(){
    freopen("sum.in","r",stdin);
    freopen("sum.out","w",stdout);
    int t;long long s;
    cin>>t;
    for(int i=1;i<=200000;i++){
        a[i]=colo(i);
        sum[i]=sum[i-1]+a[i];
    }
    while(t--){
        int n;cin>>n;
        cout<<sum[n]<<endl;
    }
    return 0;
}
原文