1¡¢Êý×é´æ´¢·¨:ÔÚ¼ÆËãµÍλÊý½×²ãµÄʱºò£¬ÎÒÃÇÒÑÖªÕâ¸öÊýµÄ½×²ã²»³¬¹ý10λÊýʱ£¬ÎÒÃÇ¿ÉÒÔ²ÉÓÃintµÄÊý¾ÝÀàÐͽøÐд洢£¬µ±¼ÆËãµÄ½×²ã¹ý¸ß£¬³¬¹ý10λÊýÉõÖÁ¸ü¶àµÄʱºò£¬Ã»ÓÐÊý¾ÝÀàÐÍ¿ÉÒÔ´æ´¢£¬´ËʱÎÒÃÇÓõ½Êý×éµÄ·½Ê½À´½øÐд洢Êý¾Ý£¬Êý×éÖÐÿһ¸öÔªËØ´ú±íһλÊý¾Ý£¬´ÓµÍµ½¸ß£¬ÒÀ´Î½«Î»Êý´æÈë¡£
±ÈÈçÏÖÔÚ¼ÆËãÒ»¸ö8£¡µÄÊý¾Ý²ÉÓÃÊý×é´æ´¢Êý¾ÝµÄģʽ½øÐмÆË㣬ÒÑÖª8£¡×îºóµÄ½á¹ûËã³öÀ´ÊÇ40320£¬¼´
4 3 2 1 0
..... | 4 | 0 | 3 | 2 | 0 |
´ËʱÊý×é´óСlen = 4,ÄÇôÏÖÔÚÒª¼ÆËã9£¡´ËʱÐèÒªÓÃ9¡Á40320£¬¶¨ÒåÒ»¸ö±äÁ¿rem±£´æµ±Ç°½øλÊý×Ö(0<=rem<=9) Æä¹ý³ÌÈçÏÂ
¢ÙremÉèÖóõÖµ0
¢Úi = 0: rem = num[0]*9 = 0 + 0 = 0, num[0] = rem % 10 = 0,rem = rem / 10 = 0
¢Ûi = 0: rem = num[0]*9 = 0 + 18 = 18, num[1] = rem % 10 = 8,rem = rem / 10 = 1
¢Üi = 0: rem = num[0]*9 = 1 + 27 = 28, num[2] = rem % 10 = 8,rem = rem / 10 = 2
¢Ýi = 0: rem = num[0]*9 = 2 + 0 = 2, num[3] = rem % 10 = 2,rem = rem / 10 = 0
¢Þi = 0: rem = num[0]*9 = 0 + 36 = 36, num[4] = rem % 10 = 6,rem = rem / 10 = 3
¢ßrem = 3; len = len + 1 = 5,num[5] = rem % 10 = 3,ren = ren / 10 = 0 ½áÊø
ÈçÏÂʾÀý³ÌÐò:
#include<stdio.h>
#define Maxlen 10000
#define N 1997
int mult(int num[],int len,int n)
{
int i,rem = 0;
for(i = 0;i < len;i++)
{
rem += num[i] * n;
num[i] = rem % 10;
rem = rem / 10;
}
if(rem > 0)
{
num[len] = rem % 10;
len++;
rem = rem /10;
}
return len;
}
void main()
{
int num[Maxlen];
int len = 1,i;
num[0] = 1;
for(i = 2; i <= N; i++)
{
len = mult(num,len,i);
}
for(i = len - 1; i >= 0; i--)
{
printf(¡°%d¡±,num[i]);
}
printf(¡°\n¡±);
}