cf B. Little Dima and Equation

http://codeforces.com/contest/460/problem/B

 1 import java.util.*;
 2 import java.math.*;
 3 public class Main {
 4     
 5     public static void main(String []args)
 6     {
 7         Scanner cin=new Scanner(System.in);
 8         int a,b,c;
 9         BigInteger a1=new BigInteger("0");
10         BigInteger a10=new BigInteger("1000000000");
11         BigInteger a3=new BigInteger("10");
12         BigInteger [][]cc=new BigInteger[100][1000];
13         BigInteger []f1=new BigInteger[1000000];
14         for(int i=1; i<=81; i++)
15         {
16             for(int j=1; j<=5; j++)
17             {
18                 BigInteger sum=new BigInteger("1");
19                 BigInteger h=new BigInteger(((Integer)i).toString());
20                 int k=1;
21                 while(k<=j)
22                 {
23                     sum=sum.multiply(h);
24                     k++;
25                 }
26                 cc[i] [j] =sum;
27             }
28         }
29         a=cin.nextInt(); b=cin.nextInt();c=cin.nextInt();
30         BigInteger h1=new BigInteger(((Integer)b).toString());
31         BigInteger h2=new BigInteger(((Integer)c).toString());
32         int cnt=0;
33         for(int i=1; i<=81; i++)
34         {
35             BigInteger a2=new BigInteger("0");
36             BigInteger hh=new BigInteger(((Integer)i).toString());
37             BigInteger ans,ans1;
38             ans=cc[i] [a] .multiply(h1).add(h2);
39             ans1=ans;
40             if(ans.compareTo(a1)<=0||ans.compareTo(a10)>0) continue;
41             while(!ans.equals(a1))
42             {
43                 a2=a2.add(ans.mod(a3));
44                 ans=ans.divide(a3);
45             }
46             if(a2.equals(hh))
47             {
48                 f1[cnt] =ans1;
49                 cnt++;
50             }
51         }
52         System.out.println(cnt);
53         for(int i=0; i<cnt; i++)
54         {
55             if(i==0) System.out.print(f1[i] );
56             else System.out.print(" "+f1[i] );
57         }
58         System.out.print("\n");
59     }
60 }
View Code

 

posted @ 2014-08-21 08:42  null1019  阅读(132)  评论(0编辑  收藏  举报