Special equations

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 178    Accepted Submission(s): 87
Special Judge

Problem Description
Let f(x) = a
nx
n +...+ a
1x +a
0, in which a
i (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 a
n to a
0 (0 < abs(a
n) <= 100; abs(a
i) <= 10000 when deg >= 3, otherwise abs(a
i) <= 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
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!
 

                 
   题目大意:
给你函数 f(x) = a
n
x
n
 +...+ a
1
x +a
0 最多N就4位,输入任意一个x使f(x)%(prime*prime)=0。如果找不到就输出NO solution!

       解题思路:开始看到中国剩余定理有点懵了,因为以前只是刷过中国剩余定理的一些定理,而且一般都是求很多同余方程。后来有队过了,然后就认真看了下。然后决定暴力做,看了下prime的范围1~10^4,枚举的话就是10^8但是暴力超时了,因为运行测试代码就花了几秒钟。 后来就不解开始看下大白里面讲中国剩余定理。。。再最后半小时左右突然灵光一现,觉得可以先对prime取模得0之后才能继续判断。然后就立马改代码。后来WA了,事实证明当时只是有一个变量写错了。。p+=mo直接每次加mo,怎么会写成了+t!!当时想的也不是很清楚,然后就又换成了p++肯定TLE。 下来之后认真思考了下,发现是没有漏洞的。

     思考过程:如果f(x)%(mo*mo)==0的必要条件是f(x)%(mo)==0.然后f(x+k*mo)%mo==0等价于f(x)%mo==0.可以自己拿纸上画一下。当时想的主要是后面有个常数项,然后在想需不需要把它放到右边去TAT!其实是不需要的。 然后就直接在0~mo一个区间里面先找f(x)%mo==0的,如果木有直接输出No sulotion!如果有的话,就+mo判断是否可以
%(mo*mo).....思路主要是根据题目给的说是要把合数分解成几个素数相乘得来的,主要是被中国剩余定理吓到了,需要掌握的知识不能只是了解。加油! 

     题目地址:Special equations

AC代码:    
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std; int a[5],n,mo,Mo; __int64 cal1(int t) //模上mo
{
int i,j;
__int64 res=a[0];
for(i=1;i<=n;i++)
{
__int64 tmp=a[i];
for(j=1;j<=i;j++)
{
tmp=tmp*t;
tmp=tmp%mo;
}
res=(res+tmp)%mo;
}
return res;
} __int64 cal2(int t) //模上mo*mo
{
int i,j;
__int64 res=a[0];
for(i=1;i<=n;i++)
{
__int64 tmp=a[i];
for(j=1;j<=i;j++)
{
tmp=tmp*t;
tmp=tmp%Mo;
}
res=(res+tmp)%Mo;
}
return res;
} int main()
{
int tes,cas,t,i,p;
scanf("%d",&tes);
for(cas=1;cas<=tes;cas++)
{
scanf("%d",&n);
int flag=0;
for(i=n;i>=0;i--)
scanf("%d",&a[i]);
scanf("%d",&mo);
Mo=mo*mo; /*for(i=n;i>=0;i--)
cout<<a[i]<<" ";
cout<<mo<<endl;*/
for(t=0;t<=mo;t++)
{
if(cal1(t)==0) //筛选能模上mo的
{
for(p=t;p<=Mo;p+=mo) //就是这里啊 TAT
{
if(cal2(p)==0)
{
flag=1;
break;
}
}
}
if(flag==1)
break;
}
if(flag==1)
printf("Case #%d: %d\n",cas,p);
else
printf("Case #%d: No solution!\n",cas);
}
return 0;
}

HDU 4569Special equations2012长沙邀请赛E题(数学知识)的更多相关文章

  1. hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。

    题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...

  2. HDU4565 && 2013年长沙邀请赛A题

    部分转自http://blog.csdn.net/crazy______/article/details/9021169 #include<cstdio> using namespace ...

  3. 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)

    Hypersphere Time Limit: 1 Second       Memory Limit: 32768 KB In the world of k-dimension, there's a ...

  4. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  5. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  6. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. HDU 4584 Building bridges (水题)

    Building bridges Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) ...

  8. Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏

    C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...

  9. codeforces#253 D - Andrey and Problem里的数学知识

    这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...

随机推荐

  1. Google Maps 学习笔记(一)2014.06.04

    1.<body onload="加载地图的函数" onunload="GUnload()"> 2.new GMap2(container,opts) ...

  2. IS-A 和 HAS-A

    IS-A关系 IS-A就是说:一个对象是另一个对象的一个分类. 下面是使用关键字extends实现继承. public class Animal{ } public class Mammal exte ...

  3. JavaSE_ API常用对象 总目录(11~14)

    JavaSE学习总结第11天_开发工具 & API常用对象111.01 常见开发工具介绍11.02 Eclipse和MyEclipse的概述11.03 Eclipse的下载安装及卸载11.04 ...

  4. BZOJ 1485: [HNOI2009]有趣的数列( catalan数 )

    打个表找一下规律可以发现...就是卡特兰数...卡特兰数可以用组合数计算.对于这道题,ans(n) = C(n, 2n) / (n+1) , 分解质因数去算就可以了... -------------- ...

  5. Cloudera Manager Service Monitor 定期挂掉问题排查

    显示:查询 Service Monitor 时发生内部错误(Error sending messages to firehose: mgmt-SERVICEMONITOR-) 1.初步排查出是smon ...

  6. 如何学习Javascript ?

    先说说学js的条件 论条件,咱是文科生,大学专业工商管理,和计算机毛关系都没:有人说英语,读了四年大学,很遗憾,咱还四级没混过:就咱这条件都学得乐呵呵的,您还等啥.当然学习JS也是有门槛的,就是你的h ...

  7. android——manifest.xml

  8. django FileFIeld和ImageField 上传路径改写

    def get_file_path(instance, filename): return 'file/document/%s/%s/%s' % (instance.period.code, inst ...

  9. C#手机充值

    C#手机充值系统开发(基于聚合数据) 说是手机充值系统有点装了,其实就是调用了聚合数据的支付接口,其实挺简单的事 但是我发现博客园竟然没有类似文章,我就个出头鸟把我的代码贡献出来吧 首先说准备工作: ...

  10. AnyEvent::HTTP 实现异步请求

    异步http: jrhmpt01:/root/async# cat a1.pl use LWP::UserAgent; use utf8; use DBI; use POSIX; use HTTP:: ...