zoukankan      html  css  js  c++  java
  • HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)

    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 = 8;
     9 
    10 int T, deg;
    11 LL phi;
    12 LL a[MAXN];
    13 
    14 LL f(LL x, LL m) {
    15     LL ret = 0, xx = 1;
    16     for(int i = 0; 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 = 0; ans < phi; ++ans) {
    28         if(f(ans, phi) == 0) {
    29             for(ret = ans; ret <= phi * phi; ret += phi)
    30                 if(f(ret, phi * phi) == 0) {
    31                     printf("Case #%d: %d
    ", t, (int)ret);
    32                     return ;
    33                 }
    34         }
    35     }
    36     printf("Case #%d: No solution!
    ", t);
    37 }
    38 
    39 int main() {
    40     cin>>T;
    41     for(t = 1; t <= T; ++t) {
    42         cin>>deg;
    43         for(int i = deg; i >= 0; --i) cin>>a[i];
    44         cin>>phi;
    45         solve();
    46     }
    47 }
    View Code
  • 相关阅读:
    osg利用矩阵投影在平面上产生阴影
    让openGL告诉你,什么是物体的移动与旋转
    利用openGL纯手工打造一个金字塔
    Java基础(四) StringBuffer、StringBuilder原理浅析
    Java基础(二) 基本类型数据类型、包装类及自动拆装箱
    Java基础(一) 八大基本数据类型
    小酌重构系列[20]——用条件判断代替异常
    小酌重构系列[19]——分解大括号
    小酌重构系列[18]——重命名
    小酌重构系列[17]——提取工厂类
  • 原文地址:https://www.cnblogs.com/oyking/p/3274797.html
Copyright © 2011-2022 走看看