zoukankan      html  css  js  c++  java
  • SCU 3578 H1N1's Problem

                               3578: H1N1's Problem

    Description

    H1N1 like to solve acm problems.But they are very busy, one day they meet a problem.
    Given three intergers a,b,c, the task is to compute a^(b^c))%317000011.
    1412, ziyuan and qu317058542 don't have time to solve it, so the turn to you for help.
    

    Input

    The first line contains an integer T which stands for the number of test cases.
    Each case consists of three integer a, b, c seperated by a space in a single line.
    1 <= a,b,c <= 100000
    

    Output

    For each case, print a^(b^c)%317000011 in a single line.
    

    Sample Input

    2
    1 1 1
    2 2 2
    
    

    Sample Output

    1
    16
    

    快速幂+欧拉函数

    地址 http://cstest.scu.edu.cn/soj/problem.action?id=3578

    因为317000011为质数,所以对他求欧拉函数就是本身减一。直接两次快速幂,一开始类型没注意用longlong结果TLE了好几次,也是教训吧。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<string>
     6 #include<queue>
     7 #include<algorithm>
     8 #include<map>
     9 #include<iomanip>
    10 #include<climits>
    11 #include<string.h>
    12 #include<numeric>
    13 #include<cmath>
    14 #include<stdlib.h>
    15 #include<vector>
    16 #include<stack>
    17 #include<set>
    18 #define INF 1e7
    19 #define MAXN 100010
    20 #define maxn 1000010
    21 #define Mod 1000007
    22 #define N 1010
    23 using namespace std;
    24 typedef long long LL;
    25 
    26 LL quick_pow(LL a, LL n, LL mod)
    27 {
    28     LL sum = 1;
    29     while (n)
    30     {
    31         if (n & 1) sum = (sum*a)%mod;
    32         a = (a%mod*a%mod) % mod;
    33         n >>= 1;
    34     }
    35     return sum%mod;
    36 }    
    37 
    38 void run()
    39 {
    40     LL a, b, c, ans;
    41     scanf("%lld%lld%lld",&a,&b,&c);
    42     ans = quick_pow(a, quick_pow(b, c, 317000010), 317000011);
    43     printf("%lld
    ",ans);
    44 }
    45 
    46 int main()
    47 {
    48     int T;
    49     scanf("%d", &T);
    50     while (T--)
    51         run();
    52     return 0;
    53 }
  • 相关阅读:
    [POJ1811]Prime Test
    Pollard-rho算法[因子分解算法]
    Miller-Rabin算法
    [POJ2886]Who Gets the Most Candies?
    Failed to connect to raw.githubusercontent.com port 443
    MAC安装flutter开发环境
    Jenkins自动化打包(Gitlab)并上传蒲公英
    Jenkins中插件下载失败的解决办法
    iOS开发~防止navigation多次push一个页面
    Jenkins 更新 jenkins.war的方法
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4366602.html
Copyright © 2011-2022 走看看