cf493E Vasya and Polynomial
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.
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 modulo 109 + 7.
2 2 2
2
2 3 3
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的更多相关文章
- 【CF493E】【数学】Vasya and Polynomial
Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...
- Polynomial Library in OpenCascade
Polynomial Library in OpenCascade eryar@163.com 摘要Abstract:分析幂基曲线即多项式曲线在OpenCascade中的计算方法,以及利用OpenSc ...
- Milliard Vasya's Function-Ural1353动态规划
Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make ...
- CF460 A. Vasya and Socks
A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- 周赛-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 ...
- FZU 2215 Simple Polynomial Problem(简单多项式问题)
Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...
- 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 ...
- 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 ...
随机推荐
- OPENFIRE 使用Hazelcast插件进行集群
参考资料:http://www.linuxidc.com/Linux/2014-01/94850.htm https://www.igniterealtime.org/projects/openf ...
- hdu 3555 Bomb 炸弹(数位DP,入门)
题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别 ...
- TLint for 虎扑体育应用源码项目
虎扑非官方客户端TLint全新Material Design设计,简洁美观支持论坛全部操作,浏览帖子.点亮.回复.引用.收藏等多项个性化设置(不同主题,不同阅读模式) TLint For 虎扑体育 更 ...
- (一)mybatis之JDBC介绍
前言:为什么在学mybatis之前要先了解JDBC呢?因为mybatis是以ORM模型为中心思想的框架,而所有的ORM模型都是基于JDBC进行封装的,不同的ORM模型对JDBC封装的强度是不一样的. ...
- Caused by: java.lang.NoClassDefFoundError: com/sun/tools/javac/util/List at
折腾了一下的时间,都没有找到解决的方案,在网上搜了一下答案都是让清理编译环境和重新打包之类的.就这样折腾一下,还没有解决问题.之所以会抛出找不到类的问题,需要排查你使用这个包的类是否存在,存在之后 查 ...
- iview 验证 trigger: 'blur,change', 同时加两个,省的每次还想input 还是 select
iview 验证 trigger: 'blur,change', 同时加两个,省的每次还想input 还是 select dataRuleValidate: { name: [{ required: ...
- smarty 运算符列表
下面是可用的运算符列表,使用中都会放到元素的中间并且用空格分隔. 注意列表中[方括号]的是可选的,而且还会列出对应PHP的表达式. 详见:Chapter 7. 内置函数 运算符 别名 语法示例 含义 ...
- iMessage, Facetime 解决办法
不需要白苹果三码,亲测可用:原帖地址: https://www.reddit.com/r/hackintosh/comments/2wohwn/getting_imessage_working_on_ ...
- nginx + 一个端口 部署多个单页应用(history模式)
目前web开发 使用一般前后端分离技术,并且前端负责路由.为了美观,会采用前端会采用h5 history 模式的路由.但刷新页面时,前端真的会按照假路由去后端寻找文件.此时,后端必须返回index(i ...
- verilog behavioral modeling ---Block statements
block statements : 1. sequential block : begin-end block 2.parallel block : fork - join bloc ...