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):
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <queue>
  5. using namespace std;
  6. typedef long long LL;
  7.  
  8. const int MAXN = ;
  9.  
  10. int T, deg;
  11. LL phi;
  12. LL a[MAXN];
  13.  
  14. LL f(LL x, LL m) {
  15. LL ret = , xx = ;
  16. for(int i = ; i <= deg; ++i) {
  17. ret = (ret + a[i] * xx) % m;
  18. xx = (xx * x) % m;
  19. }
  20. return ret;
  21. }
  22.  
  23. LL ans, ret;
  24. int t;
  25.  
  26. void solve() {
  27. for(ans = ; ans < phi; ++ans) {
  28. if(f(ans, phi) == ) {
  29. for(ret = ans; ret <= phi * phi; ret += phi)
  30. if(f(ret, phi * phi) == ) {
  31. printf("Case #%d: %d\n", t, (int)ret);
  32. return ;
  33. }
  34. }
  35. }
  36. printf("Case #%d: No solution!\n", t);
  37. }
  38.  
  39. int main() {
  40. cin>>T;
  41. for(t = ; t <= T; ++t) {
  42. cin>>deg;
  43. for(int i = deg; i >= ; --i) cin>>a[i];
  44. cin>>phi;
  45. solve();
  46. }
  47. }

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. Spring-Day03-注解注入&AOP入门-作业

    IOC(DI) —— 注解 注解入门: 在applicationContext.xml中引入context约束 打开spring-framework-4.2.4.RELEASE\docs\spring ...

  2. iOS开发CGRectGetMidX. CGRectGetMidY.CGRectGetMinY. CGRectGetMaxY. CGRectGetMinX. CGRectGetMaxX的使用

    [iOS开发]iOS开发CGRectGetMidX. CGRectGetMidY.CGRectGetMinY. CGRectGetMaxY. CGRectGetMinX. CGRectGetMaxX的 ...

  3. css3 动画应用 animations 和transtions transform在加上JavaScript 可以实现硬件加速动画。

    transitions(过渡) 被应用于元素指定的属性变化时,该属性经过一段时间逐渐的过渡到最终想要的值. 主要包括四个属性: 执行变换的属性:transition-property 变换延续的时间: ...

  4. c++ 数字和字符串的相互转换

    需要包含头文件<sstream> 字符串转化为int #include<stdio.h> #include<string.h> #include<iostre ...

  5. 剑指offer—从头到尾打印链表

    输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 递归添加...不为空就加 import java.util.ArrayList; public class Solution { pu ...

  6. MySQL数据表操作(DDL)

    一.创建数据表 语法:create table 表名称(字段 字段类型 [字段属性],字段 字段类型 [字段属性],...) [表选项]; 表选项:数据表的属性,一般包括engine.charset. ...

  7. Hadoop(19)-MapReduce框架原理-Combiner合并

    1. Combiner概述 2. 自定义Combiner实现步骤 1). 定义一个Combiner继承Reducer,重写reduce方法 public class WordcountCombiner ...

  8. C语言实例解析精粹学习笔记——32

    实例32: 编制一个包含姓名.地址.邮编和电话的通讯录输入和输出函数. 思路解析: 1.用结构体来完成姓名.地址.邮编和电话的组合. 2.结构体指针的使用. 3.malloc的使用 4.scanf函数 ...

  9. mysql学习第三天练习(多表连接)

    -- 多表连接 -- 写一条查询语句,查询员工姓名.部门名称.工作地点 select ename,dname,loc from emp,dept where emp.deptno = dept.dep ...

  10. 3124: [Sdoi2013]直径

    3124: [Sdoi2013]直径 https://www.lydsy.com/JudgeOnline/problem.php?id=3124 分析: 所有直径都经过的边,一定都是连续的一段.(画个 ...