• 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;
    }
  • 相关阅读:
    C#综合揭秘——Entity Framework 并发处理详解
    Apache2.2+Tomcat7.0整合配置详解
    python操作excel
    NameError: name ‘time‘ is not defined
    ping命令最实用的
    github使用方法
    数字证书
    网络编程
    不辣的皮特
    msdn上的“索引器”(indexer)示例
  • 原文地址:https://www.cnblogs.com/moonbay/p/2584203.html
Copyright © 2020-2023  润新知