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

cf493E Vasya and Polynomial的更多相关文章

  1. 【CF493E】【数学】Vasya and Polynomial

    Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...

  2. Polynomial Library in OpenCascade

    Polynomial Library in OpenCascade eryar@163.com 摘要Abstract:分析幂基曲线即多项式曲线在OpenCascade中的计算方法,以及利用OpenSc ...

  3. Milliard Vasya's Function-Ural1353动态规划

    Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make ...

  4. CF460 A. Vasya and Socks

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

  6. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  7. FZU 2215 Simple Polynomial Problem(简单多项式问题)

    Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...

  8. Codeforces Round #281 (Div. 2) D. Vasya and Chess 水

    D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分

    C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. 洛谷 P2947 [USACO09MAR]仰望Look Up

    题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...

  2. codevs 1487 大批整数排序(水题日常)

     时间限制: 3 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题目描述 Description !!!CodeVS开发者有话说: codevs自从换了评测机,新评测机的内存计算 ...

  3. spark简单入门

    本文由cmd markdown编辑,原始链接:https://www.zybuluo.com/jewes/note/35032 RDD是什么? RDD是Spark中的抽象数据结构类型,任何数据在Spa ...

  4. vue实现微信分享朋友圈和朋友功能

    vue实现微信分享朋友圈和朋友功能 A-A+ haibao  2018-10-25  11  21  6.2 k  百度已收录  前端开发 温馨提示:本文共3536个字,读完预计9分钟. 这两天在开发 ...

  5. MINST手写数字识别(二)—— 卷积神经网络(CNN)

    今天我们的主角是keras,其简洁性和易用性简直出乎David 9我的预期.大家都知道keras是在TensorFlow上又包装了一层,向简洁易用的深度学习又迈出了坚实的一步. 所以,今天就来带大家写 ...

  6. Delphi与JAVA互加解密AES算法

    搞了半天终于把这个对应的参数搞上了,话不多说,先干上代码: package com.bss.util; import java.io.UnsupportedEncodingException; imp ...

  7. PAT (Advanced Level) Practise - 1097. Deduplication on a Linked List (25)

    http://www.patest.cn/contests/pat-a-practise/1097 Given a singly linked list L with integer keys, yo ...

  8. Dubbo服务的搭建

    dubbo框架主要作用是基于RPC的远程调用服务管理,但是注册中心是用的zookeeper,搭建dubbo,首先要安装zookeeper,配置zookeeper... 实现功能如图所示:(存在2个系统 ...

  9. shell脚本,对MySQL数据库进行分库加分表备份

    [root@localhost wyb]# cat table_backup.sh #!/bin/bash flag= user=root pass=test mysql -u$user -p&quo ...

  10. XML解析(二) SAX解析

    XML解析之SAX解析: SAX解析器:SAXParser类同DOM一样也在javax.xml.parsers包下,此类的实例可以从 SAXParserFactory.newSAXParser() 方 ...