Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.BitSet;
- import java.util.Scanner;
- public class Main {
- public static BigInteger modmul(BigInteger a, BigInteger c){
- BigInteger x = BigInteger.ZERO, y=a.mod(c), two = BigInteger.ONE.add(BigInteger.ONE);
- while(a.compareTo(BigInteger.ZERO) > 0){
- if(a.testBit(0) == true ){
- x = x.add(y).mod(c);
- }
- y = y.multiply(two).mod(c);
- a = a.shiftRight(1);
- // if(b%2 == 1){
- // x = (x+y)%c;
- // }
- // y = (y*2)%c;
- // b /= 2;
- }
- return x.mod(c);
- }
- public static void main(String args[]){
- // 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, 8, 0, 9, 1, 8, 3, 6, 2, 7, 0, 9, 0, 9, 3, 6, 4, 5, 0, 9, 3, 6, 0, 9, 0, 9, 3, 6, 3, 6, 2, 7, 4, 5, 3, 6, 2, 7, 4, 5, 1, 8, 1, 8, 3, 6, 0, 9, 0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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};
- BigInteger res[][] = new BigInteger[509][2];
- // String res[][] = new String[509][2];
- // res[1][0] = BigInteger.ZERO;
- // res[1][1] = BigInteger.ONE;
- //
- res[2][0] = "25";
- res[2][1] = "76";
- // res[2][0] = new BigInteger("25");
- // res[2][1] = new BigInteger("76");
- // res[1].pb(0);
- // res[1].pb(1);
- // res[1].pb(5);
- // res[1].pb(6);
- //
- // res[2].pb(25);
- // res[2].pb(76);
- BigInteger p = new BigInteger("100");
- BigInteger q= new BigInteger("100");
- BigInteger v, m;
- int i, j, k;
- for( i = 3; i<=500; ++i)
- {
- p = p.multiply(BigInteger.TEN);
- int cnt = 0;
- for( j = 0; j<=9; ++j){
- for(k = 0; k<res[i-1].length; ++k){
- System.out.println(i + " " + j);
- v = q.multiply(new BigInteger(""+j));
- v = v.add(res[i-1][k]);
- // m = modmul(v, p);
- m = v.multiply(v);
- m = m.mod(p);
- if(m.compareTo(v) == 0){
- res[i][cnt++] = v;
- // System.out.printf(" %d,", j);
- // System.out.println(v.toString());
- // v = q.multiply(new BigInteger(""+(9-j)));
- // v = v.add(res[i-1][k]);
- //// m = modmul(v, p);
- // m = v.multiply(v);
- // m = m.mod(p);
- // res[i][cnt++] = v;
- }
- }
- if(cnt >= 2) break;
- }
- q = p;
- }
- int T, N;
- Scanner sc = new Scanner(System.in);
- T = sc.nextInt();
- for( int cs = 1; cs <=T; ++cs){
- N = sc.nextInt();
- // if(N > 200) continue;
- System.out.printf("Case #%d:", cs);
- if( N == 1){
- System.out.println(" 0 1 5 6");
- continue;
- }
- // System.out.println(res[i].length);
- for( i = 0; i<res[N].length; ++i){
- if(res[N][i].toString().length() == N){
- System.out.print(" "+res[N][i].toString());
- }
- }
- System.out.println("");
- }
- // for(i=3;i<=14;i++)
- // {
- // LL p=1,q=1;
- // for(j=0;j<i;j++) p*=10;
- // q=p/10;
- // int cnt=0;
- //
- // for(j=0;j<=9;j++)
- // {
- // for(k=0;k<res[i-1].size();k++)
- // {
- // LL v=(j*q+res[i-1][k]);
- // LL m=modmul(v,v,p);
- // if(m==v)
- // cnt++,res[i].pb(v);
- // }
- // if(cnt>=2) break;
- // }
- //
- // for(j=0;j<res[i].size();j++)
- // printf("%lld %lld\n",i,res[i][j]);
- // }
- // while(cin>>n)
- // {
- // LL p=1,q=1;
- // for(i=0;i<n;i++) p*=10;
- // q=p/10;
- //
- // for(i=q;i<p;i++)
- // {
- // LL m=((LL)i*i)%p;
- //
- // if(m==i)
- // printf("%lld\n",i);
- // }
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement