Codeforces Round #262 (Div. 2)
A. Vasya and Socks http://codeforces.com/contest/460/problem/A
水题暴力
1 #include<cstdio> 2 int main(){ 3 int n,m; 4 while(~scanf("%d%d",&n,&m)){ 5 int ans=0; 6 while(n){ 7 n--; 8 ans++; 9 if(!(ans%m)) n++; 10 } 11 printf("%d ",ans); 12 } 13 return 0; 14 }
B. Little Dima and Equation http://codeforces.com/contest/460/problem/B
sx=x所有位的和,要知道sx在1~1e9的x 对应的是1~81,枚举81,判断。
1 #include<cstdio> 2 typedef __int64 LL; 3 LL gxpow(int x,int n){ 4 LL res=1; 5 while(n--) res*=x; 6 return res; 7 } 8 int sum(LL x){ 9 int res=0; 10 while(x){ 11 res+=x%10; 12 x/=10; 13 } 14 return res; 15 } 16 LL ans[128]; 17 int main(){ 18 int a,b,c; 19 while(~scanf("%d%d%d",&a,&b,&c)){ 20 int la=0; 21 for(int i=1;i<=81;i++){ 22 LL x=b*gxpow(i,a)+c; 23 if(0<x&&x<1e9&&sum(x)==i){ 24 ans[la++]=x; 25 } 26 } 27 printf("%d ",la); 28 if(!la) continue; 29 for(int i=0;i<la;i++){ 30 printf("%d ",ans[i]); 31 } 32 puts(""); 33 } 34 return 0; 35 }