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条边) 且满足至少四边相等 其余两边不 ...
随机推荐
- Servlet基础知识(一)——Servlet的本质
什么是Servlet: Servlet是运行在web服务器端(web容器,如tomcat)的程序,它与Applet相对,Applet是运行在客户端的程序. Servlet的主要作用是处理客户端的请求, ...
- PHP 获取linux服务器性能CPU、内存、硬盘、进程等使用率
数据库配置文件: conn.php <?php define("MONITORED_IP", "172.16.0.191"); //被监控的服务器IP地址 ...
- Git-常用命令集合
该文章会陆续添加内容,学习网页来自http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 ...
- 转 C语言面试题大汇总
转 C语言面试题大汇总,个人觉得还是比较全地!!! \主 题: C语言面试题大汇总,个人觉得还是比较全地!!! 作 者: free131 (白日?做梦!) 信 誉 值: 100 ...
- Windows下如何建立以"."开头的文件夹
Windows资源管理器不允许创建点开头的文件或文件夹,但在cmd命令提示符下是可以的: 创建命令: md d:\.myfolder .myfolder就是以点开头的文件夹的名称
- HTML5地理定位,百度地图API,知识点熟悉
推断浏览器的兼容问题: IE9+支持地理定位,FF Chrome新版支持地理定位 if (navigator.geolocation) { alert('支持地理定位'); } e ...
- C#中两个整数相除得到带小数点的结果
有时候需要将两个整数相除,获得带小数点的float类型数.例如一个整数12345,需要变成123.45.常见与串口与硬件通讯,DSP处理浮点型比较麻烦,DSP传递来的温度等数据都以整型的方式传递,串口 ...
- c 结构体struct
struct 定义初始化 #include<stdio.h> typedef struct stuInfo { ]; //姓名 int stuId; //学号 int age; //年龄 ...
- IE7下浮动元素的内容自动换行的BUG解决方法
有时候我们想写个浮动得到这样的效果: 代码: <!doctype html> <html> <head> <meta charset="utf-8& ...
- 解决iOS7中UITableView在使用autolayout时layoutSubviews方法导致的crash
近期公司项目上线后,出现了大量的crash,发生在iOS7系统上,和UITableView相关: Auto Layout still required after executing -layoutS ...