zoukankan      html  css  js  c++  java
  • hdu 1452 数论

    这题比较好,考查了数论的许多知识,包括一个数所有因子的和的形式,以及同余公式(除法的同余公式,即求同余下的逆元)等,网上好多讨论的,这里就不再啰嗦了,直接贴代码。

    /*
    * hdu1452/win.cpp
    * Created on: 2011-10-24
    * 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;
    const int MOD = 29;
    typedef long long LL;
    int modular_exp(int a, int b, int c) {
    LL res, temp;
    res = 1 % c, 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 x;
    int firstpart, secondpart, thirdpart;
    while (scanf("%d", &x) == 1 && x > 0) {
    firstpart = modular_exp(2, 2 * x + 1, MOD) - 1;
    secondpart = modular_exp(3, x + 1, MOD) - 1;
    secondpart = (secondpart * 15) % MOD;
    thirdpart = modular_exp(167, x + 1, MOD) - 1;
    thirdpart = (thirdpart * 18) % MOD;
    int ans = firstpart * secondpart * thirdpart;
    ans %= MOD;
    printf("%d\n", ans);
    }
    return 0;
    }



  • 相关阅读:
    mint17上建立lamp环境
    iptables开始ftp
    查看mysql集群状态是否正常
    限制SSH访问源,禁止4A之外的地址跳转访问
    查看cpu、内存和硬盘
    降kipmi0的CPU
    更改密钥对
    eNSP
    划分分区GPT11
    修改虚机IP
  • 原文地址:https://www.cnblogs.com/moonbay/p/2223048.html
Copyright © 2011-2022 走看看