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 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.

Input

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

Output

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

Examples
Input
2 2 2
Output
2
Input
2 3 3
Output
1

这题是机智题啊。。。

相当于是在问有多少个数在t进制下表示是a,在a进制表示下是b

结论是当t=a=b=1的时候有无数解,t=a=b!=1的时候两解,其他情况只有最多一解

p(t)=a,说明多项式系数之和<=a,等于a的情况只有t==1的时候,这个可以特判,所以可以认为处理完之后系数之和<a

然后因为p(a)=b,把b在a进制下展开,各个位数之和<a,因为p(t)=a限制了系数之和<a

如果b在a进制下表示为一个数x,想要调整x的位数得到其他解是行不通的

因为对于x的某一位,只能通过这一位-1,下一位+a的方式在保证不违背p(a)=b的情况下调整

这样系数和加上了a-1。原来系数和p>=1,现在p+a-1>=a,这跟前面的系数和<a矛盾,所以最多一解。得到p(a)=b的解了还要验证下p(t)=a是否成立。

这题细节超多各种特判,比如a==1的时候b在a进制表示不出啥的

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL d[],len;
LL t,a,b;
int main()
{
t=read();a=read();b=read();
if (t==a&&a==b)
{
if (a==)puts("inf");
else puts("");
return ;
}
if (t==)
{
if (a==)puts("");
else
{
LL tot=,mxx=,mul=;
while (b)
{
d[++len]=b%a;
tot+=d[len];
b/=a;
mxx+=mul*d[len];
mul*=a;
}
if (tot<=a&&a-tot<=mxx&&(a-tot)%(a-)==)puts("");
else puts("");
}
return ;
}
if (a==b){puts("");return ;}
LL _a=a;
while (_a)
{
d[++len]=_a%t;
_a/=t;
}
LL sum=,mul=;
for (int i=;i<=len;i++)
{
sum+=d[i]*mul;
mul*=a;
}
if (sum==b)puts("");
else puts("");
}

cf 493E

最新文章

  1. Holographic Remoting Player
  2. 【2016 ACM/ICPC Asia Regional Qingdao Online】
  3. RMAN笔记小结
  4. bzoj1003 [ZJOI2006]物流运输
  5. ios应用启动后的自动版本检测方式
  6. ftp两种传输方式区别
  7. [转]Sql Server 2005中的架构(Schema)、用户(User)、登录(Login)和角色(Role)
  8. Android studio快捷键Mac版本
  9. zoj 2229 Ride to School
  10. 编程算法 - 数丑陋 代码(C)
  11. jacascript 构造函数、原型对象和原型链
  12. JavaScript与jQuery获取相邻控件
  13. 3.CNN-卷积神经网络推导
  14. Git应用&mdash;03分支管理和冲突解决(转载)
  15. ie兼容,手机端兼容问题
  16. 微服务监控zipkin、skywalking以及日志ELK监控系列
  17. Linux setenforce命令详解[SeLinux操作]
  18. jquery试题
  19. 第八篇:Spark SQL Catalyst源码分析之UDF
  20. python学习——练习题(13)

热门文章

  1. 转过来的Xpath语法
  2. LeetCode || 双指针 / 单调栈
  3. 【转载】WPF DataGrid 性能加载大数据
  4. Mac 下 Android Studio 安装
  5. vue 封装分页组件
  6. 牛客网NOIP赛前集训营-普及组(第二场)和 牛客网NOIP赛前集训营-提高组(第二场)解题报告
  7. MySql的基操勿六
  8. vim之替换命令
  9. fshc之请求仲裁机制(from mcu and cache)
  10. 绑定用户id,用户权限认证