Problem Description
  Let f(x) = anxn +...+ a1x +a0, in which ai (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 an to a0 (0 < abs(an) <= 100; abs(ai) <= 10000 when deg >= 3, otherwise abs(ai) <= 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!"
 
题目大意:给你一个最高4次幂的多项式,求一个x,满足f(x) mod phi² = 0。
思路:先枚举x = [0, phi),如果f(x) mod phi = 0,再枚举x2 = x,每次加phi,直到f(x) mod phi² = 0,输出结果。找不到输出No solution。
PS:我也不知道为什么是对的我看别人说是这么做的……我数论知识很少……我只知道要满足f(x) mod phi² = 0就要先满足f(x) mod phi = 0……
 
代码(62MS):
 #include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL; const int MAXN = ; int T, deg;
LL phi;
LL a[MAXN]; LL f(LL x, LL m) {
LL ret = , xx = ;
for(int i = ; i <= deg; ++i) {
ret = (ret + a[i] * xx) % m;
xx = (xx * x) % m;
}
return ret;
} LL ans, ret;
int t; void solve() {
for(ans = ; ans < phi; ++ans) {
if(f(ans, phi) == ) {
for(ret = ans; ret <= phi * phi; ret += phi)
if(f(ret, phi * phi) == ) {
printf("Case #%d: %d\n", t, (int)ret);
return ;
}
}
}
printf("Case #%d: No solution!\n", t);
} int main() {
cin>>T;
for(t = ; t <= T; ++t) {
cin>>deg;
for(int i = deg; i >= ; --i) cin>>a[i];
cin>>phi;
solve();
}
}

HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)的更多相关文章

  1. HDU 4569 Special equations(取模)

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

  2. HDU 4569 Special equations (数学题)

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

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

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

  4. HDU 4741 Save Labman No.004 2013 ACM/ICPC 杭州网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4741 题意:给你两条异面直线,然你求着两条直线的最短距离,并求出这条中垂线与两直线的交点. 需要注意的是 ...

  5. 2013 ACM-ICPC长沙赛区全国邀请赛—Special equations

    ……但是没仔细看,直接跳过了 这题直接枚举就可以过了 ;}

  6. HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)

    [题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...

  7. HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...

  8. 2013 ACM/ICPC 长沙现场赛 C题 - Collision (ZOJ 3728)

    Collision Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge There's a round medal ...

  9. HDU 4571 Travel in time(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)

    Problem Description Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. Yu ...

随机推荐

  1. 为什么有IP还需要硬件地址,或者说为什么有硬件地址还需要IP

    只用MAC 虽然每个设备都有唯一的硬件地址,但不都是MAC格式. 只用MAC的话理论上是可行的,但是其中 兼容不同的硬件地址,处理起来是非常困难的.而且数据链路层也没有必要处理网络层的逻辑. 只用IP ...

  2. Python基础—04-流程控制

    流程控制 循环结构(while) 格式 while 表达式: 语句块 执行流程:当程序执行到while语句时,首先判断表达式的真假.若表达式的值为真,则执行对应的语句块,之后返回while继续判断表达 ...

  3. javascript 中数组的创建 添加 与将数组转换成字符串 页面三种提交请求的方式

    创建js数组 var array=new Array(); Java中创建数组 private String[] array=new String[3]; 两个完全不同的,js中是可变长度的 添加内容 ...

  4. Sass 基础(四)

    当你想设置属性值的时候你可以使用字符串插入进来,另一个使用的用法是构建一个选择器. @mixin generate-sizes($class,$small,$medium,$big){ .#{$cla ...

  5. 安装sass遇到的坑

    一.安装Sass https://www.sass.hk/install/ 根据网站的步骤进行安装 Ruby版本的选择 我第一次下载是在Ruby官网上下的2.5.0版本得ruby.然而下载了之后无(不 ...

  6. npm ERR! code ENOENT (未找到文件 error no entry)

    问题: ENOENT一般是没找到文件或路径,包括因为权限问题没找到的情况 解决: 我这个是 目录选择错了 其他:

  7. 范围for语句的整理

    1.如何处理stirng中的每个字符?(来自C++Primer中文版5th中P83) 使用基于范围的for语句,比如下面的例子,输出每个字符 #include<iostream> #inc ...

  8. Java分享笔记:关于Java反射机制

    [1] 关于Java反射机制的概述 1.反射机制的概念:允许程序在执行期,借助于反射相关的API,取得任何类的内部信息,并能直接操作任意对象内部的属性和方法. 2.与反射相关的主要的API:java. ...

  9. Java常用的正则校验

    1.非负整数: (^[1-9]+[0-9]*$)|(^[0]{1}$) 或 (^[1-9]+[0-9]*$)|0 2.非正整数: (^-[1-9]+[0-9]*$)|(^[0]{1}$) 或 (^-[ ...

  10. 当安装mongodb客户端出现了Failed to load list of databases

    在装mongodb最新版(4.1.5开发版)服务后,我用robo3t打开它的时候遇到了这个问题. 最直接的解决办法就是换一个mongodb版本,https://github.com/Studio3T/ ...