简化版大数乘法
Description So far he has not made up his mind about the total amount of CDs and the number of nephews. Indeed,a given nephew may receive no CDs at all. Please help dear Uncle Jack,given the total number of CDs and the number of nephews,to calculate the number of different ways to distribute the CDs among the nephews. Input Output Sample Input #include <cstdio> #include <iostream> #include <cstring> using namespace std; int n,m; void solve() { int s[50]; memset(s,0,sizeof s); s[0]=1; int up=1; for(int i=0;i<m;i++) { for(int j=0;j<up;j++)//现将每一位的结果算出来,在进行进位,可避免将进位后的新高位又算一遍 { s[j]*=n; // cout<<"s[j]"<<s[j]; } for(int j=0;j<up;j++) { if(s[j]>9) { s[j+1]+=s[j]/10; s[j]%=10; if(j==up-1) up++; } } // cout<<"****up="<<up<<endl; } for(int i=up-1;i>=0;i--) printf("%d",s[i]); puts(""); } int main() { while(scanf("%d%d",&n,&m)&&(n||m)) { if(n==10) { printf("1"); for(int i=0;i<m;i++) printf("0"); puts(""); continue; } solve(); } return 0; } (编辑:淮安站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |