zoukankan      html  css  js  c++  java
  • 快速幂模板

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 using namespace std;
    14 #define lowbit(x) (x&(-x))
    15 #define max(x,y) (x>y?x:y)
    16 #define min(x,y) (x<y?x:y)
    17 #define MAX 100000000000000000
    18 #define MOD 1000000007
    19 #define pi acos(-1.0)
    20 #define ei exp(1)
    21 #define PI 3.141592653589793238462
    22 #define INF 0x3f3f3f3f3f
    23 #define mem(a) (memset(a,0,sizeof(a)))
    24 typedef long long ll;
    25 ll gcd(ll a,ll b){
    26     return b?gcd(b,a%b):a;
    27 }
    28 bool cmp(int x,int y)
    29 {
    30     return x>y;
    31 }
    32 const int N=100005;
    33 const int mod=1e9+7;
    34 ll qpow(int x,int n)
    35 {
    36     ll ans=1;
    37     while(n){
    38         if(n&1)  // n & 1 等价于 (n % 2) == 1
    39             ans*=x;
    40         x*=x;
    41         n>>=1;// n >>= 1 等价于 n /= 2
    42     }
    43     return ans;
    44 }
    45 int main()
    46 {
    47     std::ios::sync_with_stdio(false);
    48     ll a,n;
    49     while(cin>>a>>n){
    50         cout<<qpow(a,n)<<endl;
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    __attribute__ 总结
    linux文件夹打包命令
    学习ARM的一些基本知识,个人整理
    备忘录之 —— .bashrc(IC工具篇)
    GitHub的基本使用
    02: SocketServer服务
    01: socket模块
    08: python基础练习题
    07: 高阶函数&异常处理
    06: 面向对象
  • 原文地址:https://www.cnblogs.com/wydxry/p/7300162.html
Copyright © 2011-2022 走看看