The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum

Posted c4lnn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum相关的知识,希望对你有一定的参考价值。

Link
题意:
定义 (S_b(n))(b) 进制下 (n) 的数位和
已知 (N)(b)
(sum_{n=1}^{N}{S_b(n)})
思路:
因为测试数据很多,所以要预处理前缀和
(S_b(n)=S_b(n/b)+n\%b Longrightarrow sum[b][n]=sum[b][n/b]-sum[b][n/b-1]+n\%b+sum[b][n-1])
代码:

#include<bits/stdc++.h>

using namespace std;
 
int s[11][1000001]={0};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=2;i<=10;i++)
        for(int j=1;j<=1000000;j++) {
            s[i][j]=s[i][j/i]+j%i+s[i][j-1];
            if(j/i) s[i][j]-=s[i][j/i-1];
        }   
    int T;cin>>T;
    int n,b;
    for(int i=1;i<=T;i++) {
        cin>>n>>b;
        cout<<"Case #"<<i<<": "<<s[b][n]<<endl;
    }
    return 0;
}

以上是关于The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum的主要内容,如果未能解决你的问题,请参考以下文章

The Preliminary Contest for ICPC Asia Yinchuan 2019

The Preliminary Contest for ICPC Asia Shenyang 2019

The Preliminary Contest for ICPC Asia Shanghai 2019

The Preliminary Contest for ICPC Asia Shanghai 2019

The Preliminary Contest for ICPC Asia Xuzhou 2019

The Preliminary Contest for ICPC Asia Nanchang 2019