「CF493E」Vasya and Polynomial

2014年12月4日5,0006

Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a0 + a1x1 + … + anxn. Numbers ai are called coefficients of a polynomial, non-negative integer n is called adegree 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.

Input

The input contains three integer positive numbers no greater than 1018.

Output

If there is an infinite number of such polynomials, then print “infwithout quotes, otherwise print the reminder of an answer modulo 109 + 7.

Sample test(s)
input

output

input

output

 

题解

真是神题啊。。。

做了好多英文阅读。。。如有错误请指正。。。

以下默认多项式系数非负

t=a=b=1,有无数解

t=a=b=n(n>1),此时有两解 p(x)=a p(x)=x

以下证明其余情况最多一解

—————————————————————————————-

p(t)=a可以得出多项式的系数和<a,t=1时系数和<=a下面会另外讨论

我们考虑把b在a进制下表示,就能得到一个多项式使得p(a)=b

—–如 1497 = 2 × 93 + 4 ×9 + 3 -> p(x) = 2 x3 + 4 x + 3

由于多项式的系数和<=a,所以我们无法通过调整系数使得存在另一个多项式p'(x)满足p'(a)=b

因为将多项式的任意一个x^k分解

—–如2 x3 + 4 x + 3 -> x3 + 13 x + 3

至少会使得p(x)系数和增加a-1,而p(x)系数和>=1,调整后>=a

(p(x)系数和等于0的情况即a=b,若t<>a=b则显然只有一解p(x)=a)

*但若t=1,且p(x)系数和为1,调整后p'(x)系数和为a,形如p(1)=k,p(k)=k^q,则唯一解为p(x)=k*x^(q-1)

—————————————————————————————-

特判后将b在a进制下表示得到系数后带入t检验即可

 

avatar
1 Comment threads
5 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
hzwercoolwyj Recent comment authors
  Subscribe  
提醒
王文海

楼主,你程序有个bug
1 1 10
这组数据会在 log(b)/log(a) 里面 变成 log(10)/0