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 (数学题)

    题目地址: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(枚举+数论)(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? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

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

  7. HDU 5698 大组合数取模(逆元)

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

  8. hdu 4474 大整数取模+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(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

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

随机推荐

  1. 细分java环境中的JDK、JVM、JRE

    细分java环境中的JDK.JVM.JRE 近来小看了下Android,扑面而来一堆概念JDK.JVM.JRE.SDK.NDK.ADT.缕了一下,其中JDK.JVM.JRE是java环境的东西,而SD ...

  2. C#委托的介绍(delegate、Action、Func、predicate)

    委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递.事件是一种特殊的委托. 1.委托的声明 (1). delegate delegate我们常用到的一种声明   Deleg ...

  3. JAVA并发编程J.U.C学习总结

    前言 学习了一段时间J.U.C,打算做个小结,个人感觉总结还是非常重要,要不然总感觉知识点零零散散的. 有错误也欢迎指正,大家共同进步: 另外,转载请注明链接,写篇文章不容易啊,http://www. ...

  4. CentOS yum 源的配置与使用

    一.yum 简介 yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器.起初是由yellow dog 这一发行版的 ...

  5. js 的 protype 小总结

    这里是对该文的总结: 1.Javascript中对象的prototype属性的解释是:返回对象类型原型的引用.   2.原型法的主要思想是,现在有1个类A,我想要创建一个类B,这个类是以A为原型的,并 ...

  6. kmeans算法并行化的mpi程序

    用c语言写了kmeans算法的串行程序,再用mpi来写并行版的,貌似参照着串行版来写并行版,效果不是很赏心悦目~ 并行化思路: 使用主从模式.由一个节点充当主节点负责数据的划分与分配,其他节点完成本地 ...

  7. tst、cmp、bne、beq指令

    1.tst:逻辑处理指令,用于把一个寄存器的内容和另一个寄存器的内容或立即数进行按位的与运算,并根据运算结果更新CPSR中条件标志位的值.当前运算结果为1,则Z=0:当前运算结果为0,则Z=1 cmp ...

  8. 【IDEA】intellij idea 插件推荐

    CSDN 2016博客之星评选结果公布    [系列直播]零基础学习微信小程序!      "我的2016"主题征文活动   博客的神秘功能 [IDEA]intellij idea ...

  9. 嵌入式Linux驱动学习之路(二十五)虚拟网卡驱动程序

    一.协议栈层次对比 设备无关层到驱动层的体系结构 1).网络协议接口层向网络层协议提供提供统一的数据包收发接口,不论上层协议为ARP还是IP,都通过dev_queue_xmit()函数发送数据,并通过 ...

  10. 记一次从邻居无线路由渗透到邻居PC

    起因:因为房东的网太垃圾 决定自己动手丰衣足食蹭邻居的网 结果发现一个信号超好的无线路由0x01踩点 无意中发现TP-LINK_28C0这个无线信号特别的好 看起来就肯定知道是隔壁邻居的 抓了一下包 ...