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. .net mvc System.Web.Optimization 、System.Data.Entity.Infrastructure找不到

    在MVC4的开发中,如果在App_Start目录下BundleConfig.cs类没有找不到引用System.Web.Optimization,可以使用程序包管理控制台进行安装到使用的项目 打开 工具 ...

  2. SMACSS:一个关于CSS的最佳实践-2.Base Rules

    回顾 在上一篇SMACSS:一个关于CSS的最佳实践-Overview中,讲到SMACSS将CSS Rules分为5个Categories: Base Layout Module State Them ...

  3. SSIS: 使用Lookup 和 Cache transformation 进行数据匹配简单介绍

    本文将讲解Cache transformation的使用方式,并且用Lookup transformation进行匹配. 背景 如下图,我们的产品目标表中有些有尺寸信息有些没有.我们需要用Cache组 ...

  4. iOS 7 标签栏控制器进行模态视图跳转后变成透明

    要解决此问题,需要设置tabBar的如下属性: self.tabBar.translucent = NO;

  5. spring4.1.3+springmvc+mybatis3.2.1整合

    注意:这里使用了mybatis3.2.1版本,刚开始用了3.4.1的版本,会报一个很奇怪的错(java.lang.AbstractMethodError: org.mybatis.spring.tra ...

  6. python 10min系列之实现增删改查系统

    woniu-cmdb 奇技淫巧--写配置文件生成增删改查系统 视频教程 项目主页跪求github给个star, 线上demo,此页面都是一个配置文件自动生成的 详细的文章介绍和实现原理分析会发布在我的 ...

  7. widget intent重复问题

    今天在做android widget时发现点击任意widget时只会更新最后一个widget 原来是requestCode的问题 Intent intent = new Intent(WidgetPr ...

  8. [HDU 3336]Count the String[kmp][DP]

    题意: 求一个字符串的所有前缀串的匹配次数之和. 思路: 首先仔细思考: 前缀串匹配. n个位置, 以每一个位置为结尾, 就可以得到对应的一个前缀串. 对于一个前缀串, 我们需要计算它的匹配次数. k ...

  9. 通过自定义window来实现提示框效果

    #import <UIKit/UIKit.h>#import <Foundation/Foundation.h> @interface ZMStatuBarHud : NSOb ...

  10. 《数字图像处理原理与实践(MATLAB版)》一书之代码Part6

    本文系<数字图像处理原理与实践(MATLAB版)>一书之代码系列的Part6,辑录该书第281至第374页之代码,供有须要读者下载研究使用.代码运行结果请參见原书配图,建议下载代码前阅读下 ...