1.链接:http://www.patest.cn/contests/ds/2-06
2.思路:模拟摆竖式相加,因为同样位置上的数字同样,那么同一位上的加法就能够用乘法来表示
3.代码:
#include<cstdio> #include<iostream> #include<cstring> using namespace std; char s[1000000]; int main() { int a,n; while(scanf("%d%d",&a,&n)==2) { if(n==0) { printf("0 "); continue; } memset(s,'0',sizeof(s)); int t=0; int j=0; for(int i=n; i>=1; i--) { int x=a*i+t; s[j++]+=x%10; t=x/10; } while(t>0) { s[j++]+=t%10; t=t/10; } for(int i=j-1; i>=0; i--) { if(i==0) printf("%c ",s[i]); else printf("%c",s[i]); } } return 0; }