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 ...
随机推荐
- How to install Eclipse?
http://askubuntu.com/questions/26632/how-to-install-eclipse How to install Eclipse? up vote113down v ...
- 洛谷P1628 合并序列
题目描述 有N个单词和字符串T,按字典序输出以字符串T为前缀的所有单词. 输入输出格式 输入格式: 输入文件第一行包含一个正整数N: 接下来N行,每行一个单词,长度不超过100: 最后一行包含字符串T ...
- Nodejs + Jshint自动化静态代码检查
1. 目的 提交代码前能够自动化静态代码检查,提高代码质量 2. 准备 1. Nodejs安装: 官方地址:http://nodejs.org/ 安装说明:根据电脑配置下载对应的版本进行 ...
- ActiveAndroid问题no such table解决总结
android.database.sqlite.SQLiteException: no such table at android.database.sqlite.SQLiteConnection ...
- Django ORM 查询操作
queryset中支持链式操作 book=Book.objects.all().order_by('-nid').first() 只要返回的是queryset对象就可以调用其他的方法,直到返回的是对象 ...
- Java Miniui实现批量上传文件demo 201906221520
可能需要的jar包: 需要miniui(类似easyui). Test2019062201.jsp <%@ page language="java" contentType= ...
- Spring-2-官网学习
spring生命周期回调 结合生命周期机制(官网提供) 1.实现InitializingBean接口重写void afterPropertiesSet() throws Exception;方法 使用 ...
- java中regex参考
在Sun的Java JDK 1.40版本中,Java自带了支持正则表达式的包,本文就抛砖引玉地介绍了如何使用java.util.regex包. 可粗略估计一下,除了偶尔用Linux的外,其他Linu ...
- 看结果,测试?java中的String类 字符串拆分成字符串数组 判定邮箱地址 字符串比较 参数传递?
看结果1? package com.swift; class ArrayString { public static void main(String[] args) { String str = & ...
- iMessage, Facetime 解决办法
不需要白苹果三码,亲测可用:原帖地址: https://www.reddit.com/r/hackintosh/comments/2wohwn/getting_imessage_working_on_ ...