设为首页 加入收藏

TOP

hdu4589 Special equations(数论)
2014-11-23 18:58:17 来源: 作者: 【 】 浏览:6
Tags:hdu4589 Special equations 数论

Special equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 206 Accepted Submission(s): 108
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   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
4
2 1 1 -5 7
1 5 -2995 9929
2 1 -96255532 8930 9811
4 14 5458 7754 4946 -2210 9601

Sample Output
Case #1: No solution!
Case #2: 599
Case #3: 96255626
Case #4: No solution!

Source
2013 ACM-ICPC长沙赛区全国邀请赛——题目重现

题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有f(x+p)%p=0。

所以我们可以开始从0到p枚举x,当f(x)%p=0,然后再从x到p*p枚举,不过每次都是+p,找到了输出即可,没有的话No solution!,这里只需要枚举到pri*pri,这个证法和前面的一样

#include   
  
int a[6],pri,n;  
  
__int64 getf(int x,int i)  
{  
    int j;  
    __int64 sum=0;  
    for(j=0;j

int a[6],pri,n;

__int64 getf(int x,int i)
{
	int j;
	__int64 sum=0;
	for(j=0;j 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇有序队列(sorted_queue)的C++实.. 下一篇hdu 1026 Ignatius and the Princ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 教程 - W3Sch (2025-12-26 12:00:51)
·Python基础教程,Pyt (2025-12-26 12:00:48)
·神仙级python入门教 (2025-12-26 12:00:46)
·“我用Java 8”已成 (2025-12-26 11:19:54)
·下载 IntelliJ IDEA (2025-12-26 11:19:52)