超大数求解,怎么做啊,头都想大了
怎么输出1000!685*9=
个位相乘取个位,进十位, 下一位相乘进位与个位相加,是否进位,进位与十位相加,相进,依此例推.
ABC*D=C*D%10
(C*D/10+B*D%10)>9?-10
B*D/10+A*D%10+1??>9?
A*D/10
5 4+2=6 7+4=1→1 5+1=6
5616 6165
0123 3210
[ 本帖最后由 忘了 于 2010-6-11 21:05 编辑 ]
#include<stdio.h> #include <windows.h> int main(int argc, char* argv[]) { SYSTEMTIME STime1; SYSTEMTIME STime2; ::GetLocalTime(&STime1); int PLace[50000]={0}; int ex[50000]={0}; int P[50000]={0}; unsigned long n,k,i,N,j=1,l; int flag=1,temp; printf("Please input a number:\n"); scanf("%u",&n); N=n; for (;n/10;) { PLace[j]=n%10; n=n/10; j++; } PLace[j]=n; l=j; for (j=1;j<=l;j++) { P[j]=PLace[j]; } for (k=N;k>=3;k--) { for (i=1;i<k-1;i++) { for(j=1;;j++) { temp=PLace[j]; PLace[j]=(temp+P[j]+ex[j-1])%10; ex[j]=(temp+P[j]+ex[j-1])/10; if (j==l&&ex[l]==0) { break; } else if (j==l&&ex[l]>0) { l++; } } j=1; } for (j=1;j<=l;j++) { P[j]=PLace[j]; } } for (j=l;j>=1;j--) { printf("%d",PLace[j]); } printf("\n"); ::GetLocalTime(&STime2); printf("Use Time : %uhours %uminutes %useconds %umilliseconds\n",STime2.wHour-STime1.wHour,STime2.wMinute-STime1.wMinute,STime2.wSecond-STime1.wSecond,STime2.wMilliseconds-STime1.wMilliseconds); getchar(); return 0; }
int main(int argc, char* argv[]) { int nArray[100000]; int nNumber; int nTemp; int nCarry = 0; //进位 int nDigital = 1; //位数 clock_t cStart; clock_t cEnd; double dDuration; printf("输入阶乘上限:"); scanf("%d", &nNumber); nArray[0] = 1; //从2开始阶乘 cStart = clock(); for (int i = 2; i <= nNumber; i++) { for (int j = 0, nCarry = 0; j < nDigital; j++) { nTemp = nArray[j] * i + nCarry; //每一位乘以i 加上进位 nArray[j] = nTemp % 10; //只留一位 nCarry = nTemp / 10; //剩下的进位 } while (nCarry > 0) //判断是否有进位 { ++nDigital; //有进位位数加一位 nArray[nDigital - 1] = nCarry % 10; //把除以10的余数值给 上一位 nCarry = nCarry / 10; //十位以上给进位 } } cEnd = clock(); //以为从数组下标0开始进位,所以从大到小倒着输出 for (int k = nDigital - 1; k >= 0; k--) { printf("%d",nArray[k]); } printf("\r\n"); dDuration = (double)(cEnd - cStart) / CLOCKS_PER_SEC; printf("计算用时: %f秒\r\n", dDuration); return 0; }