HDU-4569 Special equations (数学)
来源:互联网 发布:美国加拿大合并 知乎 编辑:程序博客网 时间:2024/05/02 03:21
Special equations
http://acm.hdu.edu.cn/showproblem.php?pid=4569
Special Judge
Problem Description
Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known integers. We call f(x) 0 (mod m) congruence equation. If m is a composite, we can factor m into powers of primes and solve every such single equation after which we merge them using the Chinese Reminder Theorem. In this problem, you are asked to solve a much simpler version of such equations, with m to be prime's square.
Input
The first line is the number of equations T, T<=50.
Then comes T lines, each line starts with an integer deg (1<=deg<=4), meaning that f(x)'s degree is deg. Then follows deg integers, representing an to a0 (0 < abs(an) <= 100; abs(ai) <= 10000 when deg >= 3, otherwise abs(ai) <= 100000000, i<n). The last integer is prime pri (pri<=10000).
Remember, your task is to solve f(x) 0 (mod pri*pri)
Then comes T lines, each line starts with an integer deg (1<=deg<=4), meaning that f(x)'s degree is deg. Then follows deg integers, representing an to a0 (0 < abs(an) <= 100; abs(ai) <= 10000 when deg >= 3, otherwise abs(ai) <= 100000000, i<n). The last integer is prime pri (pri<=10000).
Remember, your task is to solve f(x) 0 (mod pri*pri)
Output
For each equation f(x) 0 (mod pri*pri), first output the case number, then output anyone of x if there are many x fitting the equation, else output "No solution!"
Sample Input
42 1 1 -5 71 5 -2995 99292 1 -96255532 8930 98114 14 5458 7754 4946 -2210 9601
Sample Output
Case #1: No solution!Case #2: 599Case #3: 96255626Case #4: No solution!
看到Special Judge和中国剩余定理就有点怕,直接题解了...发现这对数学好的人来说又是一道简单题
题目只求任意一个x使f(x)%(pri*pri)=0,满足这个的必要条件是f(x)%(pri)=0,所以先在0~pri中枚举x,若找不到符合条件的则无解,找到则令x+=pri再次在x~pri*pri中枚举x,若找不到符合条件的则无解,找到则为答案。
#include <cstdio>#include <algorithm>using namespace std;long long n,a[5],pri,ppri,x;long long f(long long num) { long long fx=0,t=1; for(int i=0;i<=n;++i) { fx+=a[i]*t; t*=num; } return fx;}int main() { int T,kase=0; scanf("%d",&T); while(kase<T) { scanf("%I64d",&n); for(int i=n;i>=0;--i) scanf("%I64d",a+i); scanf("%I64d",&pri); printf("Case #%d: ",++kase); x=0; while(x<pri) { if(f(x)%pri==0) break; ++x; } if(x==pri) printf("No solution!\n"); else { ppri=pri*pri; while(x<ppri) { if(f(x)%ppri==0) break; x+=pri; } if(x>=ppri) printf("No solution!\n"); else printf("%I64d\n",x); } } return 0;}
0 0
- HDU-4569 Special equations (数学)
- [HDU 4569] Special equations (数学+技巧+脑洞)
- HDU 4569 Special equations
- Special equations(数学筛)
- HDU 4569 Special equations (数学题)
- 数学题-hdu-4569-Special equations
- HDU 4569 Special equations 枚举
- Special equations ----(hdu4569)数学思维
- hdu 4569 Special equations ( 必要条件缩小范围后暴力)
- HDU-4569 Special equations (利用数学知识巧妙降低复杂度)
- Hdu 4569 Special equations 2013长沙邀请赛
- HDU 4569 Special equations 解题报告
- hdu 4589 Special equations
- HDU 4569 Special equations(思维)——2013 ACM-ICPC长沙赛区全国邀请赛
- hdu 1496 Equations(数学:暴力|| HASH)
- Special equations
- HDU 1840--Equations【数学】【水题】
- Equations(数学,水)
- (原创)socket学习实验(一)——利用C 语言socket抓取一个网页内容
- Linux 同步方法剖析--内核原子,自旋锁和互斥锁
- adb shell中设置android系统内部环境变量!
- 面对自己:如何让自己成为真正的程序员
- ReactNative学习二
- HDU-4569 Special equations (数学)
- Android ADB中使用find命令
- Andrid进阶_Ksoap2访问WebService出现错误SoapFault
- static的作用
- iOS开发-UIView之动画效果的实现方法
- IOS把url中含有的中文字符转化为UTF8编码方法
- Java构建工具:Ant vs Maven vs Gradle
- 机器学习基础(三十八) —— 从几率到逻辑斯函数
- 写博客还是有必要的