ZOJ 3167 Find 7 Faster Than John Von Neumann

#include<stdio.h>
#include<stdlib.h>
main()
{
      int k,m,n,t,i;
      int dig[100];
      while(scanf("%d%d",&k,&m)!=EOF)
      {
          for(i=0;i<100;i++)
               dig[i]=0;
          t=1;dig[0]=1;
          for(n=1;n<100;n++)
          {
            for(i=0;i<t;i++)
              dig[i]*=m;
            for(i=0;i<t;i++)//t作限制,避免做无用的运算
            if(dig[i]>9)
            {
               dig[i+1]+=dig[i]/10;
                dig[i]=dig[i]%10;
            }
            while(dig[i]>9)//dig[i]指上一个if之后得到的最后一个数组元素 ,判断其是否大于10
            {
               dig[i+1]+=dig[i]/10;
               dig[i]=dig[i]%10;
               i++;
             }
            while(dig[i]>0)  i++;
            t=i;
            if(dig[k-1]==7)
            {
               printf("%d\n",n);
               break;
            }
          }
     } 
return 0;
system("pause");
}
             

你可能感兴趣的:(ZOJ 3167 Find 7 Faster Than John Von Neumann)