cf B. Little Dima and Equation

时间:2022-04-28 16:07:47

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

 import java.util.*;
import java.math.*;
public class Main { public static void main(String []args)
{
Scanner cin=new Scanner(System.in);
int a,b,c;
BigInteger a1=new BigInteger("");
BigInteger a10=new BigInteger("");
BigInteger a3=new BigInteger("");
BigInteger [][]cc=new BigInteger[][];
BigInteger []f1=new BigInteger[];
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
BigInteger sum=new BigInteger("");
BigInteger h=new BigInteger(((Integer)i).toString());
int k=;
while(k<=j)
{
sum=sum.multiply(h);
k++;
}
cc[i] [j] =sum;
}
}
a=cin.nextInt(); b=cin.nextInt();c=cin.nextInt();
BigInteger h1=new BigInteger(((Integer)b).toString());
BigInteger h2=new BigInteger(((Integer)c).toString());
int cnt=;
for(int i=; i<=; i++)
{
BigInteger a2=new BigInteger("");
BigInteger hh=new BigInteger(((Integer)i).toString());
BigInteger ans,ans1;
ans=cc[i] [a] .multiply(h1).add(h2);
ans1=ans;
if(ans.compareTo(a1)<=||ans.compareTo(a10)>) continue;
while(!ans.equals(a1))
{
a2=a2.add(ans.mod(a3));
ans=ans.divide(a3);
}
if(a2.equals(hh))
{
f1[cnt] =ans1;
cnt++;
}
}
System.out.println(cnt);
for(int i=; i<cnt; i++)
{
if(i==) System.out.print(f1[i] );
else System.out.print(" "+f1[i] );
}
System.out.print("\n");
}
}