数的长度---nyoj69

超时

#include <stdio.h>
#include <string.h>
#define M 1000001
int shu[M];

int main()
{
 int n, x, i, j, p, e, m;
 scanf("%d", &n);
 while(n--){
               
            memset(shu, 0, sizeof(shu));
   shu[1] = 1;
   scanf("%d", &x);
#if 0
   for(i = 1, p = 1; i <= x; ){

     for(j = 1; j <= p; j++, i++)/*将大数的各个位数与乘数相乘*/
     {
      shu[j] *= i;
      if(shu[j] >= 10)
      {
       shu[j+1] = shu[j] / 10;
       shu[j] %= 10;
       p++;
      }
     
     }
     
   }
#endif
   p = 1;
   for(i = 1; i <= x; i++)
   {
    e = 0;
    m = 0;
    for(j = 1; j <= p; j++)
    {
     e = shu[j] * i + m;
     shu[j] = e % 10;
     m = e / 10;
     if(j == p && m)
     {
      p++;
     }
    
    }

   }
   printf("%d\n", p);

 }
 return 0;
}

posted @ 2013-08-22 18:06  心中的阿哲  阅读(193)  评论(0编辑  收藏  举报