What is the sum of the digits of the number 2^1000?

前端 未结 10 1926
别跟我提以往
别跟我提以往 2021-01-02 03:13

This is a problem from Project Euler, and this question includes some source code, so consider this your spoiler alert, in case you are interested in solving it yourself. It

10条回答
  •  清歌不尽
    2021-01-02 03:47

     main()
     {
       char c[60];
      int k=0;
         while(k<=59)
          {
        c[k]='0';
       k++;
    
        }
           c[59]='2';
           int n=1;
         while(n<=999)
           {
           k=0;
         while(k<=59)
          {
            c[k]=(c[k]*2)-48;
            k++;
          } 
        k=0;
         while(k<=59)
            {
            if(c[k]>57){ c[k-1]+=1;c[k]-=10;   }
           k++;
             }
           if(c[0]>57)
            {
             k=0;
             while(k<=59)
               {
             c[k]=c[k]/2;
              k++;
               }
               printf("%s",c);
                 exit(0);
               }
    
                n++;
                }
              printf("%s",c);
                  } 
    

提交回复
热议问题