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 ...
随机推荐
- 洛谷 P2947 [USACO09MAR]仰望Look Up
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...
- 洛谷 P1531 I Hate It
题目背景 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 题目描述 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的 ...
- 关键字: on
关键字: on 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户. 在使用left jion时,on和where条件的区别如下: 1. on条件是在生成 ...
- BZOJ4513 SDOI2016 储能表 记忆化搜索(动态规划)
题意: 题面中文,不予翻译:SDOI2016储能表 分析: 据说有大爷用一些奇怪的方法切掉了这道题%%%%% 这里用的是大众方法——动态规划. 其实这是一道类似于二进制数位dp的动态规划题,(但是实际 ...
- windows 7虚拟机与主机不能互ping通,但是都能与网关ping通
这里是在Windows 10的环境下使用VMware安装了一个Windows 7的虚拟机,虚拟机中是使用桥接的方式.结果发现虚拟机不能与物理机互通,但是却能与网关互通.查看虚拟机和物理机的IP发现都是 ...
- 【Java_基础】JVM内存模型与垃圾回收机制
1. JVM内存模型 Java虚拟机在程序执行过程会把jvm的内存分为若干个不同的数据区域来管理,这些区域有自己的用途,以及创建和销毁时间. JVM内存模型如下图所示 1.1 程序计数器 程序计数器( ...
- (40)zabbix监控web服务器访问性能
zabbix web监控介绍 在host列可以看到web(0),在以前的版本这项是独立出来的,这个主要实现zabbix对web性能的监控,通过它可以了解web站点的可用性以及性能. 最终将各项指标绘制 ...
- Mac单机模式安装启动Kafka
1.下载kafka,网址: https://www.apache.org/dyn/closer.cgi?path=/kafka/2.0.0/kafka_2.12-2.0.0.tgz 2.移动tar包到 ...
- 2018年,最经典的26个JavaScript面试题和答案!
根据 Stack Overflow 的 2018 年度调查,JavaScript 连续六年成为最常用的编程语言.所以我们必须面对这样的现实,JavaScript 已经成为全栈开发技能的基石,在全栈开发 ...
- linux kernel如何处理大端小端字节序
(转)http://blog.csdn.net/skyflying2012/article/details/43771179 最近在做将kernel由小端处理器(arm)向大端处理器(ppc)的移植的 ...