zoukankan      html  css  js  c++  java
  • hdu1420 Prepared for New Acmer ——快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1420

    题目大意:

      中文题。

    题目思路:

      赤裸裸的快速幂。呵呵

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <cstdlib>
     5 using namespace std;
     6 #define LL long long
     7 LL m;
     8 LL Po(LL a, LL b) {
     9   LL ans = 1;
    10   while (b) {
    11     if (b&1) {
    12       ans = (ans * a) % m;
    13       b--;
    14     }
    15     b /= 2; a = a * a % m;
    16   }
    17   return ans;
    18 }
    19 int main(void) {
    20   LL n, a, b;
    21 #ifndef ONLINE_JUDGE
    22   freopen("1420.in", "r", stdin);
    23 #endif
    24   scanf("%I64d", &n);
    25   while (n--) {
    26     scanf("%I64d%I64d%I64d", &a, &b, &m);
    27     printf("%I64d\n", Po(a, b));
    28   }
    29   return 0;
    30 }

    WA了几次……原因就是输入输出要用%I64d,用%lld或者类型不用LL就出错。题目本身是说要范围10^6,如果平方一下,显然就超int了,所以不能用int

  • 相关阅读:
    slenium截屏
    效率提升
    R语言网页爬虫
    高性能计算
    数据操作
    数据库操作
    面向对象编程
    元编程
    R 的内部机制
    数据处理
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/3112759.html
Copyright © 2011-2022 走看看