Codeforces Round #281 (Div. 2) E. Vasya and Polynomial 数学 思考题
来源:互联网 发布:hadoop结构化数据存储 编辑:程序博客网 时间:2024/05/16 08:53
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 1000000000000000007ll 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;}
- Codeforces Round #281 (Div. 2) E. Vasya and Polynomial 数学 思考题
- Codeforces 493E Vasya and Polynomial(数学)
- CodeForces 493 E.Vasya and Polynomial(数学)
- CodeForces 493 E.Vasya and Polynomial(数学)
- Codeforces Round #206 (Div. 2) E. Vasya and Beautiful Arrays
- Codeforces Round #206 (Div. 2) E-Vasya and Beautiful Arrays
- E - Vasya and Polynomial
- Codeforces Round #281 (Div. 2) A. Vasya and Football
- Codeforces Round #281 (Div. 2) A - Vasya and Football
- Codeforces Round #281 (Div. 2)-D. Vasya and Chess
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball&D. Vasya and Chess
- Codeforces Round #425 (Div. 2) E-Vasya and Shifts (高斯消元)
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- Codeforces Round #206 (Div. 2) B. Vasya and Public Transport
- Codeforces Round #206 (Div. 2) C. Vasya and Robot
- Codeforces Round #262 (Div. 2) A. Vasya and Socks
- Codeforces Round #324 (Div. 2)C. Marina and Vasya
- Linux系统管理-(2)--磁盘的挂载与卸载
- android imageLoader 使用缓存策略
- Flume - 重新编译源码
- 关于实例化,以及面向对象new 与不new的区别
- android的广播事件
- Codeforces Round #281 (Div. 2) E. Vasya and Polynomial 数学 思考题
- PID_MAX_DEFAULT
- 2015.08极速下载Android SDk
- H5中form表单中新增属性
- 第52讲:Scala中路径依赖代码实战详解学习笔记
- 程序员笔试知识点整理]
- 约翰·卡马克和他的id Software
- Spring mvc+jackson+jquery 返回json数据出现整合出现包冲突问题
- 12222222222222222222222222222