题解:AT_agc066_b [AGC066B] Decreasing Digit Sums

· · 题解

思路

首先发现 5 这个数很强啊,你发现大部分 f(5^i)<f(5^{i+1}),你考虑把若干个 5^i 拼起来用 0 隔开,那么一次减少的量十分巨大,且增加的量一定不如减少的量,然后写个高精度就做完了。

代码

#include<bits/stdc++.h>
#define int long long 
using namespace std;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<23],*p1=buf,*p2=buf;
int read(){char c=getchar();int p=0,flg=1;while(c<'0'||c>'9'){if(c=='-') flg=-1;c=getchar();}while(c>='0'&&c<='9'){p=p*10+c-'0';c=getchar();}return p*flg;}
int n,a[10010];
signed main(){
    a[0]=1;a[1]=5;vector<int>ans;ans.push_back(5);
    int lst=0;
    for(int i=1;i<=150;i++){
        int tag=0;for(int j=1;j<=a[0];j++){
            int v=a[j]*5+tag;
            if(v<10) a[j]=v,tag=0;else a[j]=v%10,tag=v/10;
        }if(tag) a[++a[0]]=tag;
        for(int j=1;j<=10;j++) ans.push_back(0);
        int sum=0;
        for(int j=1;j<=a[0];j++) ans.push_back(a[j]),sum+=a[j];
        assert(lst>sum);
    }reverse(ans.begin(),ans.end());for(auto i:ans) cout<<i;
    return 0;
}