• HDU4569 Special equations


     1 /*
     2  HDU4569 Special equations
     3  http://acm.hdu.edu.cn/showproblem.php?pid=4569
     4  数论 
     5  题意:f(x)为一n次方程求是否存在x, s.t. f(x)=0 (mod p^2)
     6  其中p为质数
     7  首先,我们只需考虑0-p中的x即可,因为其他的x总可以先取模
     8  到这个区间,因此可以在1e4内找到f(x)=0(mod p)的x
     9  考虑到 x=0(mod p^2) => x=0(mod p) 
    10  因此只需在这些x中找是否满足x=0(mod p^2)即可
    11  当我们找到一个满足x0=0(mod p)的x0时,
    12  就的到了通解x=x0+k*p;在通解中找满足题意的x即可
    13  */
    14 #include <cstdio>
    15 #include <algorithm>
    16 #include <cstring>
    17 #include <cmath>
    18 #include <vector>
    19 #include <queue>
    20 #include <iostream>
    21 #include <map>
    22 #include <set>
    23 //#define test
    24 using namespace std;
    25 const int Nmax=1005;
    26 long long m;
    27 long long num[15];
    28 long long n;
    29 long long fac(long long x,long long mod)
    30 {
    31     long long ans=0LL;
    32     long long base=1LL;
    33     x=x%mod;
    34     for(int i=0;i<=n;i++)
    35     {
    36         ans=(ans+((num[i]*base)%mod))%mod;
    37         base=(base*x)%mod;
    38     }
    39     ans=ans%mod;
    40     while(ans<0)
    41         ans+=mod;
    42     return ans;
    43 }
    44 long long ans;
    45 int is()
    46 {
    47     for(long long i=0LL;i<=m;i++)
    48     {
    49         //if(i==9716LL)
    50             //printf("YES,%lld
    ",fac(i,m*m));
    51         if(!fac(i,m))
    52         {
    53             //printf("fac(i,m*m):%lld
    ",fac(i,m*m));
    54             for(long long j=0LL;j<=m;j++)
    55             {
    56                 if(!fac(i+j*m,m*m))
    57                 {
    58                     ans=i+j*m;
    59                     return 1;
    60                 }
    61             }
    62             return 0;
    63         }
    64     }
    65     return 0;
    66 }
    67 int main()
    68 {
    69     #ifdef test
    70     freopen("test.in","r",stdin);
    71     #endif
    72     int t; 
    73     //long long a=935124339326LL;
    74     //a=-a;
    75     //printf("%lld
    ",a%(9811LL);
    76     scanf("%d",&t);
    77     for(int ttt=1;ttt<=t;ttt++)
    78     {
    79         scanf("%lld",&n);
    80         for(int i=n;i>=0;i--)
    81             scanf("%lld",&num[i]);
    82         scanf("%lld",&m);
    83         printf("Case #%d: ",ttt);
    84         if(is())
    85             printf("%lld
    ",ans);
    86         else
    87             printf("No solution!
    ");
    88     }
    89     return 0;
    90 }
  • 相关阅读:
    iOS-触摸事件、手势识别、摇晃事件、耳机线控
    iOS-App生命周期
    Foundation框架—时间处理对象NSDate
    Kali linux渗透测试的艺术 思维导图
    数据结构_二叉树遍历
    数据结构_数值转换
    <转载>Mac下,使用sshpass让iterm2支持多ssh登录信息保存
    <转载>iTerm2使用技巧
    Maven打包编译找不到com.sun.crypto.provider.SunJCE类
    MySQL自动设置create_time和update_time
  • 原文地址:https://www.cnblogs.com/BBBob/p/6657995.html
Copyright © 2020-2023  润新知