打表。把每一种情况的和都计算出来,这个可以按位统计贡献。询问的时候输出即可。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-6; void File() { freopen("D:\in.txt","r",stdin); freopen("D:\out.txt","w",stdout); } template <class T> inline void read(T &x) { char c = getchar(); x = 0; while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } int ans[100010]; void init() { for(int i=0;i<=99999;i++) //00000-99999 { ans[i]=0; int tmp=i; while(tmp) { int x=tmp%10; tmp=tmp/10; ans[i]=ans[i]+266664*x; } ans[i]=ans[i]-i; } } int main() { init(); int n; while(~scanf("%d",&n)) { for(int i=0;i<=99999;i++) { if(ans[i]!=n) continue; printf("%05d ",i); } } return 0; }