HDU 4569 Special equations (数学题)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4569
题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0.
题解: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!
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=1;
const LL mod=1000000007LL;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL xi[6],p2,p;
int n; LL ff(LL x,LL k)
{
LL sum=0,ans=1;
for(int i=0;i<=n;i++)
{
sum=(sum+xi[i]*ans)%k;
ans*=x;
}
return (sum+k)%k;
} void xiaohao()
{
LL i,x,x2;
for(x=0;x<p;x++)
{
LL t=ff(x,p);
if(t%p==0)
{
for(x2=x;x2<p2;x2+=p)
{
LL t2=ff(x2,p2);
if(t2%p2==0)
{
printf("%I64d\n",x2);
return ;
}
}
}
}
printf("No solution!\n");
} int main()
{
int i,j,T,ca=0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=n;i>=0;i--)
scanf("%I64d",&xi[i]);
scanf("%I64d",&p);
p2=p*p;
printf("Case #%d: ",++ca);
xiaohao();
}
return 0;
}
HDU 4569 Special equations (数学题)的更多相关文章
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
- HDU 4569 Special equations(数学推论)
题目 //想不出来,看了解题报告 /* 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有 ...
- HDU4569 Special equations
/* HDU4569 Special equations http://acm.hdu.edu.cn/showproblem.php?pid=4569 数论 题意:f(x)为一n次方程求是否存在x, ...
- HDU 5839 Special Tetrahedron
HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...
- HDU 5839 Special Tetrahedron (计算几何)
Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
- HDU 5839 Special Tetrahedron 计算几何
Special Tetrahedron 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...
- HDU 3395 Special Fish(拆点+最大费用最大流)
Special Fish Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 5839 Special Tetrahedron (2016CCPC网络赛08) (暴力+剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5839 在一个三维坐标,给你n个点,问你有多少个四面体(4个点,6条边) 且满足至少四边相等 其余两边不 ...
随机推荐
- jjjjQuery选择器
此文为作者自用复习文章 jQuery选择器: 它不仅继承了CSS选择器简洁的语法, 还继承了其获取页面便捷高效的特点, 它还拥有更加完善的处理机制: 但jQuery选择器获取元素后,为该元素添加的是行 ...
- 穿透的 div ( pointer-events )
pointer-events 是一個滿有趣的 CSS3 屬性,雖然主要是針對 SVG ,但其中幾個屬性應用在 div 上也是頗有意思.顧名思義,這是一個針對滑鼠事件的屬性,預設值為 auto,若值為 ...
- spring拦截器的定义
(一).拦截器的定义 1.为什么需要拦截器:在做身份认证或者是进行日志的记录时,我们需要通过拦截器达到我们的目的 2.什么事拦截器:在AOP(Aspect-Oriented Programming)中 ...
- static_cast,const_cast,dynamic_cast,reinterpret_cast
除非必要,尽量不要对变量进行强制转换.这是因为强制转换是存在风险的,但实际上在某种情况下,转型是必需的. 旧式C转型方式为(type)expression,即由一对小括号加上一个对象名称组成,而这种语 ...
- BZOJ 1176: [Balkan2007]Mokia( CDQ分治 + 树状数组 )
考虑cdq分治, 对于[l, r)递归[l, m), [m, r); 然后计算[l, m)的操作对[m, r)中询问的影响就可以了. 具体就是差分答案+排序+离散化然后树状数组维护.操作数为M的话时间 ...
- codeforces 630P. Area of a Star
题目链接 圆上n个点等距离分布, 求构成的星星的面积. 我们可以求三角形OAB的面积, ∠CAE = 1/2 ∠ COE = PI/n, 那么∠CAO = PI/2n, ∠AOB非常好求, 就是PI/ ...
- 【转】几个常用的Oracle存储过程
http://blog.bossma.cn/database/some-oracle-storing-process/ 几个常用的Oracle存储过程 发布时间:2008年1月6日 / 分类:Data ...
- POJ 1222 EXTENDED LIGHTS OUT(高斯消元)
[题目链接] http://poj.org/problem?id=1222 [题目大意] 给出一个6*5的矩阵,由0和1构成,要求将其全部变成0,每个格子和周围的四个格子联动,就是说,如果一个格子变了 ...
- Android Studio 代码混淆
新建一个项目,Android Studio默认关闭代码混淆开关,在build.gradle文件中,如下图所示的minifyEnabled 开关,因此如果需要混淆代码,需将false改为true,然后在 ...
- xmu1214: 购物
1214: 购物 Time Limit: 500 MS Memory Limit: 64 MBSubmit: 10 Solved: 5[Submit][Status][Web Board] Des ...