2007-02-20

【Q10220】I Love Big Numbers !

題目: http://acm.uva.es/p/v102/10220.html

說明:
  這題必須運用陣列求解,應該還算簡單!

程式下載: http://yaushung.googlepages.com/2007022001.c

程式內容:

#include <stdio.h>

#define
LENGTH 2568

int main() {
int table[LENGTH] = {1} ;
int input ;
int i, j, carry, temp, jj, start ;
while(scanf("%d", &input)!=EOF) {
start = jj = 0 ;
for(i=2 ; i<=input ; i++) {
carry = 0 ;
while(table[jj]==0)
start = jj++ ;
for(j=start ; j<LENGTH ; j++) {
temp = table[j] * i + carry ;
table[j] = temp % 10 ;
carry = temp / 10 ;
}
}
temp = table[0] ;
table[0] = 1 ;
if(start==0)
start++ ;
for(i=start ; i<LENGTH ; i++) {
temp += table[i] ;
table[i] = 0 ;
}
printf("%d\n", temp) ;
}
return 0 ;
}

沒有留言: