HDU 4569 Special equations(取模)

时间:2021-07-07 10:05:50
Special equations

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

  Let f(x) = a nn +...+ 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)

最多N就4位,输入任意一个x使f(x)%(prime*prime)=0。

首先要找一个 f(x) % prime = 0 ,只有满足这个条件 f(x) % (prime * prime) 才有可能等于0,对于f(x) % prime,可以枚举 0 - prime,如果满足条件那么在判断( x + prime * k ) % (prime * prime)是否满足条件
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
LL a[], P;
int deg;
bool func(LL x, LL mod)
{
LL res = , now = ;
for (int i = ; i <= deg; i++)
{
res = (res + now * a[i]) % mod;
now = (now * x) % mod;
}
if (res % mod)
return ;
return ;
}
int main()
{
int test;
scanf("%d", &test);
for (int t = ; t <= test; t++)
{
scanf("%d", &deg);
for (int i = deg; i >= ; i--)
{
scanf("%I64d", &a[i]);
}
scanf("%I64d", &P);
LL ans = -;
int flag = false;
for (LL i = ; i <= P; i++)
{
if (func(i, P))
continue;
for (LL j = i; j <= P * P; j += P)
{
if (func(j, P * P))
continue;
flag = true;
ans = j;
break;
}
if (flag)
break;
}
printf("Case #%d: ", t);
if (flag)
printf("%I64d\n", ans);
else
printf("No solution!\n");
}
return ;
}
 
 
 
 

HDU 4569 Special equations(取模)的更多相关文章

  1. HDU 4569 Special equations &lpar;数学题&rpar;

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4569 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p ...

  2. HDU 4569 Special equations(数学推论)

    题目 //想不出来,看了解题报告 /* 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有 ...

  3. HDU 4569 Special equations(枚举&plus;数论)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...

  4. HDU 4632 区间DP 取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...

  5. HDU 6211 卡常数取模 预处理 数论

    求所有不超过1e9的 primitive Pythagorean triple中第2大的数取模$2^k$作为下标,对应a[i]数组的和. 先上WIKI:https://en.wikipedia.org ...

  6. hdu 3944 DP&quest; 组合数取模&lpar;Lucas定理&plus;预处理&plus;帕斯卡公式优化&rpar;

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  7. HDU 5698 大组合数取模&lpar;逆元&rpar;

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  8. hdu 4474 大整数取模&plus;bfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4474 (a*10+b)%c = ((a%c)*10+b%c)%c; 然后从高位开始枚举能填的数字填充, ...

  9. HDU 5895 Mathematician QSC&lpar;矩阵乘法&plus;循环节降幂&plus;除法取模小技巧&plus;快速幂&rpar;

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

随机推荐

  1. redhat7 yum安装

    redhat 的更新包只对注册的用户生效,所以我们自己手动更改成CentOS 的更新包,CentOS几乎和redhat是一样的,所以无需担心软件包是否可安装,安装之后是否有问题,另外CentOS公司去 ...

  2. Slip&period;js(移动端跟随手指滑动组件,零依赖)

    Slip.js可用于移动端滑动banner,移动端整屏滑动等效果,个人觉得用于移动端滑动banner比较好,不会和iScroll.js起冲突,因为它不依赖任何其它的js库. Html: <!do ...

  3. oracle在线重定义表

    在一个高可用系统中,如果需要改变一个表的定义是一件比较棘手的问题,尤其是对于7×24系统.Oracle提供的基本语法基本可以满足一般性修改,但是对于把普通堆表改为分区表,把索引组织表修改为堆表等操作就 ...

  4. POJ 1179 IOI1998 Polygon

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5472   Accepted: 2334 Description Polyg ...

  5. Lua教程

    Lua中的类型与值 Lua中的表达式 Lua中的语句 Lua中的函数 Lua中的闭包 Lua 中 pairs 和 ipairs 的区别 Lua中的迭代器与泛型for Lua中的协同程序 Lua中__i ...

  6. &lbrack;转帖&rsqb;Docker save and load镜像保存

    Docker save and load镜像保存 https://www.cnblogs.com/zhuochong/p/10064350.html docker save 和 load 以及 imp ...

  7. ROS Learning-009 beginner&lowbar;Tutorials ROS服务 和 ROS参数

    ROS Indigo beginner_Tutorials-08 ROS服务 和 ROS参数 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14 ...

  8. 转载【微信小程序】:微信小程序滚动Tab选项卡:左右可滑动切换&lpar;仿某宝&rpar;

    1.本文转载至:http://blog.csdn.net/sophie_u/article/details/71745125 2.效果: 3.最终效果如上.问题: 1).tab标题总共8个,所以一屏无 ...

  9. Python 的 Matplotlib 画图库

    Matplotlib安装 NumPy库方便数值运算,但枯燥的数据并不利于人们的直观理解. 数据需要可视化. Matplotlib:一个数据可视化函数库 使用前需要安装  利用Python自带 ...

  10. 【Oracle 12c】CUUG OCP认证071考试原题解析(32)

    32.choose the best answer View the Exhibit and examine the data in EMP and DEPT tables. In the DEPT ...