zoukankan      html  css  js  c++  java
  • nyoj 102 次方求模

     

    次方求模

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:3
     
    描述

    求a的b次方对c取余的值

     
    输入
    第一行输入一个整数n表示测试数据的组数(n<100)
    每组测试只有一行,其中有三个正整数a,b,c(1=<a,b,c<=1000000000)
    输出
    输出a的b次方对c取余之后的结果
    样例输入
    3
    2 3 5
    3 100 10
    11 12345 12345
    样例输出
    3
    1
    10481
    来源
    [张云聪]原创
    上传者
    张云聪
    这题可以当做模板题
    View Code
     1  
     2 /*********************************
     3 /   Problem:
     4 /   Algorithm:
     5 /   Language:   C++
     6 /   Compiler:   MinGW
     7 /   Date:       12/08/08
     8 /
     9 /   Copyright (C) wujianwei
    10 /   All rights reserved.
    11 ********************************/
    12 
    13 #include <iostream>
    14 #include <cstdio>
    15 #include <cstring>
    16 #include <cmath>
    17 #include <vector>
    18 #include <cstring>
    19 #include <queue>
    20 #include <stack>
    21 #include <algorithm>
    22 #include <set>
    23 
    24 using namespace std;
    25 
    26 #define INF 0x7fffffff
    27 #define EPS 1e-12
    28 #define MOD 1000000007
    29 #define PI 3.141592653579798
    30 #define N 100005
    31 const int MAX=1<<28;
    32 typedef long long LL;
    33 //typedef __int64 INT
    34 
    35 LL poww(LL a,LL b,LL c)
    36 {
    37     LL ans=1,t=a;
    38     while(b)
    39     {
    40         if(b&1) ans=ans*t%c;
    41         t=t*t%c;
    42         b>>=1;
    43     }
    44     return ans;
    45 }
    46 
    47 int main()
    48 {
    49     int T;
    50     LL a,b,c;
    51     scanf("%d",&T);
    52     while(T--)
    53     {
    54         //scanf("%lld%lld%lld",&a,&b,&c);
    55         cin>>a>>b>>c;
    56         cout<<poww(a,b,c)<<endl;
    57     }
    58     return 0;
    59 }
    60         
  • 相关阅读:
    c++教程目录
    ANDROID教程目录
    ArrayBuffer
    读懂 ECMAScript 规格
    编程风格
    Module 的加载实现
    Module 的语法
    修饰器Decorator
    Class 的继承
    SQL Server 2008 R2导出数据脚本的方法
  • 原文地址:https://www.cnblogs.com/wujianwei/p/2637008.html
Copyright © 2011-2022 走看看