zoukankan      html  css  js  c++  java
  • hdu1852快速幂取余

    开始题目看岔了,以为还挺复杂的,打了半天才发现题目是说对2008^N求约数和再计算,不是对N,于是就很简单了。。。

    /*
     * hdu1852/win.cpp
     * Created on: 2012-7-10
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    
    typedef long long LL;
    
    int modular_exp(int a, int b, int c) {
        LL res, temp;
        res = 1, temp = a % c;
        while(b) {
            if(b & 1) {
                res = res * temp % c;
            }
            temp = temp * temp % c;
            b >>= 1;
        }
        return (int)res;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int N, K, M;
        while(scanf("%d%d", &N, &K) == 2) {
            if(N == 0 && K == 0) {
                break;
            }
            int p1 = modular_exp(2, 3 * N + 1, K);
            p1 = (p1 + K - 1) % K;
            int p2 = modular_exp(251, N + 1, K * 250);
            p2 = (p2 + K * 250 - 1) % (K * 250);
            p2 /= 250;
            M = (p1 % K) * (p2 % K) % K;
            printf("%d\n", modular_exp(2008, M, K));
        }
        return 0;
    }
  • 相关阅读:
    Linux-diff命令
    Linux-查看文件内容命令
    Linux-tar命令
    Linux-df -h命令
    Linux-mkdir命令&touch命令
    Linux-cd命令&pwd命令
    Linux-zip命令&rz命令&sz命令
    Linux-npm install命令&脚本命令
    Linux-tail命令
    Linux-cat命令
  • 原文地址:https://www.cnblogs.com/moonbay/p/2584203.html
Copyright © 2011-2022 走看看