HDU 4569Special equations2012长沙邀请赛E题(数学知识)
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
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.
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)
2 1 1 -5 7
1 5 -2995 9929
2 1 -96255532 8930 9811
4 14 5458 7754 4946 -2210 9601
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!
%(mo*mo).....思路主要是根据题目给的说是要把合数分解成几个素数相乘得来的,主要是被中国剩余定理吓到了,需要掌握的知识不能只是了解。加油!
#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题(数学知识)的更多相关文章
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- HDU4565 && 2013年长沙邀请赛A题
部分转自http://blog.csdn.net/crazy______/article/details/9021169 #include<cstdio> using namespace ...
- 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)
Hypersphere Time Limit: 1 Second Memory Limit: 32768 KB In the world of k-dimension, there's a ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- HDU 2802 F(N)(简单题,找循环解)
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU 4584 Building bridges (水题)
Building bridges Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- 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 ...
- codeforces#253 D - Andrey and Problem里的数学知识
这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件. 于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大. 我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦. ...
随机推荐
- ie6兼容性,还需要测试么?迷茫。。。
最近公司网站在谷歌,火狐上测试都没有问题,但是在ietest,ie6上出现兼容问题 ,由于ietest好几次打开ie6都报错(尝试卸载重新安装几次无果),下载virtualbox安装自带ie6的xp系 ...
- struts2入门
好久没有动博客了.今天看了一下慕课网的视频,简单了解一下struts2. 首先是在项目中引入struts2的文件,有一个比较简单的方法就是可以直接右键项目MyEclipse->Project f ...
- java 汉字转拼音
先决条件: pinyin4j.jar(Pinyin4j是一个流行的Java库,支持中文字符和拼音之间的转换.拼音输出格式可以定制.) 下载地址:http://pan.baidu.com/share/l ...
- Git跨平台中文乱码临时解决方案
Git 是一个非常优秀的分布式版本控制系统,最初为Linux Kernel版本管理进行量身定做.优点是,和其他版本控制系统相比,稳定,速度快,跨平台,易学易用,无需要花费成本.更多优点请点击阅读:ht ...
- 加装 ImageMagick 性能更佳!
1. 下载 Download ImageMagick 以此文件ImageMagick-6.9.1-10-Q16-x64-dll-win进行,第二次开发的研发 2. 安装 Install ImageMa ...
- hdu 4349 Xiao Ming's Hope lucas
题目链接 给一个n, 求C(n, 0), C(n, 1), ..........C(n, n)里面有多少个是奇数. 我们考虑lucas定理, C(n, m) %2= C(n%2, m%2)*C(n/2 ...
- 【转载】关于Python脚本开头两行的:#!/usr/bin/python和# -*- coding: utf-8 -*-的作用 – 指定文件编码类型
1.#!/usr/bin/python 是用来说明脚本语言是 python 的 是要用 /usr/bin下面的程序(工具)python,这个解释器,来解释 python 脚本,来运行 python 脚 ...
- Delphi 预编译指令
<Delphi下深入Windows核心编程>(附录A Delphi编译指令说明)Delphi快速高小的编译器主要来自Object PASCAL的严谨,使用Delphi随时都在与编译器交流, ...
- Servlet 基础知识
8.Response 8.1.getOutputStream和getWriter方法分别用于得到输出二进制数据.输出文本数据的ServletOutputStream .Printwriter对象. ...
- How to setup linked servers for SQL Server and Oracle 64 bit client
感谢作者:Tim Ford. 图文并茂. 原帖地址: http://www.mssqltips.com/sqlservertip/1433/how-to-setup-linked-servers-fo ...