1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
using namespace std;
int main(){
int a[1000][12],i,j,count,m,n,sum[12]={0,0,0,0,0,0,0,0,0,0,0,0}; // an array for each integer
for(i=0;i<=999;i++){
a[i][11]=1; // all of the array for each integer is filled
for(j=0;j<=10;j++) a[i][j]=0; // with 0 , except last one filled with 1
}
for(i=1;i<=1000;i++){
for(count=1;count<=i;count++){ // each of the integer x multiplied x time
for(j=0;j<=11;j++){
a[i-1][j]*=i;
for(m=0;m<=999;m++){ // in this for structure
for(n=11;n>=0;n--){ // while an integer in the arrat is greater than 10
while(a[m][n]>=10){ // reduce while it becomes less than 10
a[m][n-1]++;
a[m][n]-=10;
}
}
}
}
}
}
for(j=11;j>=2;j--){ // adding all of the 1000 array ;
for(i=0;i<=999;i++){
sum[j]+=a[i][j];
}
}
for(j=11;j>=0;j--){ // reducing each integer in array while it becomes less than 10
while(sum[j]>=10){
sum[j-1]++;
sum[j]-=10;
}
}
for(i=2;i<=11;i++) cout<<sum[i]<<" ";
cout<<endl<<sum[0]<< " "<<sum[1];
}
|