Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.04 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.BitSet;
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7. public class Main {
  8.    
  9.     public static BigInteger modmul(BigInteger a, BigInteger c){       
  10.         BigInteger x = BigInteger.ZERO, y=a.mod(c), two = BigInteger.ONE.add(BigInteger.ONE);
  11.        
  12.         while(a.compareTo(BigInteger.ZERO) > 0){
  13.             if(a.testBit(0) == true ){
  14.                 x = x.add(y).mod(c);
  15.             }
  16.             y = y.multiply(two).mod(c);
  17.             a = a.shiftRight(1);
  18. //          if(b%2 == 1){
  19. //              x = (x+y)%c;
  20. //          }
  21. //          y = (y*2)%c;
  22. //          b /= 2;
  23.         }
  24.        
  25.         return x.mod(c);
  26.     }
  27.     public static void main(String args[]){
  28. //      int arr[] = {0,0, 1,1, 2,2, 3, 6, 0, 9, 0, 9, 1, 8, 2, 7, 1, 8, 2, 7, 1, 8, 1, 8, 0, 9, 0, 9, 4, 5, 2, 7, 3, 6, 4, 5, 2, 7, 2, 7, 0, 9, 3, 6, 2, 7, 2, 7, 0, 9, 0, 9, 1, 8, 3, 6, 3, 6, 0, 9, 1, 8, 4, 5, 0, 9, 0, 9, 0, 9, 0, 9, 1, 8, 3, 6, 0, 9, 1, 8, 0, 9, 3, 6, 2, 7, 3, 6, 2, 7, 4, 5, 3, 6, 2, 7, 4, 5, 2, 7, 4, 5, 4, 5, 0, 9, 0, 9, 0, 9, 1, 8, 1, 8, 1, 8, 3, 6, 3, 6, 1, 8, 0, 9, 1, 8, 4, 5, 0, 9, 0, 9, 4, 5, 3, 6, 3, 6, 1, 8, 2, 7, 3, 6, 0, 9, 0, 9, 0, 9, 1, 8, 0, 9, 0, 9, 4, 5, 1, 8, 3, 6, 0, 9, 2, 7, 0, 9, 1, 8, 0, 9, 3, 6, 1, 8, 1, 8, 0, 9, 1, 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 2, 7, 1, 8, 1, 8, 1, 8, 4, 5, 4, 5, 2, 7, 4, 5, 4, 5, 0, 9, 3, 6, 4, 5, 0, 9, 0, 9, 3, 6, 0, 9, 0, 9, 3, 6, 4, 5, 1, 8, 4, 5, 2, 7, 0, 9, 0, 9, 1, 8, 1, 8, 0, 9, 1, 8, 3, 6, 1, 8, 0, 9, 1, 8, 0, 9, 3, 6, 4, 5, 4, 5, 3, 6, 0, 9, 0, 9, 0, 9, 4, 5, 0, 9, 0, 9, 3, 6, 4, 5, 4, 5, 2, 7, 4, 5, 3, 6, 2, 7, 0, 9, 1, 8, 3, 6, 4, 5, 2, 7, 4, 5, 1, 8, 4, 5, 4, 5, 0, 9, 4, 5, 2, 7, 2, 7, 1, 8, 3, 6, 2, 7, 3, 6, 3, 6, 3, 6};
  29.         BigInteger res[][] = new BigInteger[509][2];
  30. //      String res[][] = new String[509][2];
  31.        
  32. //      res[1][0] = BigInteger.ZERO;
  33. //      res[1][1] = BigInteger.ONE;
  34. //     
  35.         res[2][0] = "25";
  36.         res[2][1] = "76";
  37.        
  38. //      res[2][0] = new BigInteger("25");
  39. //      res[2][1] = new BigInteger("76");
  40. //      res[1].pb(0);
  41. //      res[1].pb(1);
  42. //      res[1].pb(5);
  43. //      res[1].pb(6);
  44. //     
  45. //      res[2].pb(25);
  46. //      res[2].pb(76);
  47.        
  48.         BigInteger p = new BigInteger("100");      
  49.         BigInteger q= new BigInteger("100");   
  50.         BigInteger v, m;
  51.        
  52.         int i, j, k;
  53.         for( i = 3; i<=500; ++i)
  54.         {
  55.             p = p.multiply(BigInteger.TEN);
  56.             int cnt = 0;
  57.            
  58.             for( j = 0; j<=9; ++j){
  59.                
  60.                 for(k = 0; k<res[i-1].length; ++k){
  61.                     System.out.println(i + " " +  j);
  62.                     v = q.multiply(new BigInteger(""+j));
  63.                     v = v.add(res[i-1][k]);
  64. //                  m = modmul(v, p);
  65.                     m = v.multiply(v);
  66.                     m = m.mod(p);
  67.                    
  68.                     if(m.compareTo(v) == 0){
  69.                         res[i][cnt++] = v;
  70. //                      System.out.printf(" %d,", j);
  71. //                      System.out.println(v.toString());
  72.                        
  73. //                      v = q.multiply(new BigInteger(""+(9-j)));
  74. //                      v = v.add(res[i-1][k]);
  75. ////                        m = modmul(v, p);                      
  76. //                      m = v.multiply(v);
  77. //                      m = m.mod(p);
  78. //                      res[i][cnt++] = v;
  79.                     }
  80.                 }
  81.                 if(cnt >= 2) break;
  82.             }      
  83.        
  84.            
  85.             q = p;
  86.         }
  87.        
  88.         int T, N;
  89.         Scanner sc = new Scanner(System.in);
  90.        
  91.         T = sc.nextInt();
  92.         for( int cs = 1; cs <=T; ++cs){
  93.            
  94.             N = sc.nextInt();
  95. //          if(N > 200) continue;
  96.            
  97.             System.out.printf("Case #%d:", cs);
  98.             if( N == 1){
  99.                 System.out.println(" 0 1 5 6");
  100.                 continue;
  101.             }
  102.            
  103. //          System.out.println(res[i].length);
  104.             for( i = 0; i<res[N].length; ++i){
  105.                 if(res[N][i].toString().length() == N){
  106.                     System.out.print(" "+res[N][i].toString());
  107.                 }
  108.             }
  109.             System.out.println("");
  110.         }
  111.            
  112.        
  113.        
  114. //      for(i=3;i<=14;i++)
  115. //      {
  116. //          LL p=1,q=1;
  117. //          for(j=0;j<i;j++) p*=10;
  118. //          q=p/10;
  119. //          int cnt=0;
  120. //         
  121. //          for(j=0;j<=9;j++)
  122. //          {
  123. //              for(k=0;k<res[i-1].size();k++)
  124. //              {
  125. //                  LL v=(j*q+res[i-1][k]);
  126. //                  LL m=modmul(v,v,p);
  127. //                  if(m==v)
  128. //                      cnt++,res[i].pb(v);
  129. //              }
  130. //              if(cnt>=2) break;
  131. //          }
  132. //         
  133. //          for(j=0;j<res[i].size();j++)
  134. //              printf("%lld %lld\n",i,res[i][j]);
  135. //      }
  136. //      while(cin>>n)
  137. //      {
  138. //          LL p=1,q=1;
  139. //          for(i=0;i<n;i++) p*=10;
  140. //          q=p/10;
  141. //         
  142. //          for(i=q;i<p;i++)
  143. //          {
  144. //              LL m=((LL)i*i)%p;
  145. //             
  146. //              if(m==i)
  147. //                  printf("%lld\n",i);
  148. //          }
  149. //      }
  150.     }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement