Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a functionP(x) = a0 + a1x1 + ... + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called a degree of a polynomial.
Vasya has made a bet with his friends that he can solve any problem with polynomials. They suggested him the problem: "Determine how many polynomials P(x) exist with integer non-negative coefficients so that , and
, where
and b are given positive integers"?
Vasya does not like losing bets, but he has no idea how to solve this task, so please help him to solve the problem.
The input contains three integer positive numbers no greater than 1018.
If there is an infinite number of such polynomials, then print "inf" without quotes, otherwise print the reminder of an answer modulo109 + 7.
2 2 2
2
2 3 3
1
十分有意思的一题,看到这个式子,应该很熟悉,很像那个b转化为a进制,a转化为t进制,刚开始想,分解为n进制只有一种方法,那这个式子,不就最多一个解么,再看,有多解的情况就是t a为1时,存在特殊解(也就是不是进制转化的情况,系数特殊值),所以,分类讨论,情况还是十分多的。
1.如果t = a = b = 1;无穷解,因为,n可以取到任意数。
2.如果是 1 a a^x存在一个解。n取到x - 1;特殊的x = 0时,a > 1,无解
3.t != 1 a = b时,有1 个解,就是a0 = a时。
4.t = a = b != 1时有两个解,也就是a0 = a 与,a1 = 1 ao= 0;
5.其它情况,最多只有一个解(因为进制转化,只有一种方法),把b 化为a进制,a 化为t进制,比较其系数相同就可以了。
复杂度为转化进制的复杂度为o(log(n));
#define N 205
#define M 100005
#define maxn 205
#define MOD 1000000000000000007
ll t,a,b,p[N];
int pn;
void Update(ll x,ll y){
pn = 0;
if(y == 1) return ;
while(x){
p[pn++] = x % y;
x /= y;
}
}
bool check(ll x,ll m){
ll ans = 0,s = 1;
FI(pn){
ans += p[i] * s;
s *= m;
if(ans > x) return false;
}
if(ans == x) return true;
else return false;
}
void GetAns(ll b,ll a,ll t){
Update(b,a);
if(check(a,t))
printf("1\n");
else
printf("0\n");
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while(cin>>t)
{
cin>>a;cin>>b;
if(t == 1){
if(a == b && b == t) printf("inf\n");
else {
if(a > b){
printf("0\n");
}
else {
ll s = 1;
while(s < b){
if(a == 1) break;
s *= a;
}
if(s == b) printf("1\n");
else {
GetAns(b,a,t);
}
}
}
continue;
}
if(a == b && b == t) printf("2\n");
else if(a == b) printf("1\n");
else GetAns(b,a,t);
}
//fclose(stdin);
//fclose(stdout);
return 0;
}