神秘钥匙-快速幂题

           

#include<cstdio>
long long  PowerMod (long long a, int b, int c) 
{  
    int  ans = 1; 
    a = a % c; 
    while(b>0) {  
        if(b % 2 == 1) 
            ans = (ans * a) % c; 
        b = b/2;       //   b>>=1;
        a = (a * a) % c; 
    } 
    return ans; 
}  
int main()
{
	int n;
	long long ans;
	scanf("%d", &n);
	ans=PowerMod(2,n-1,1000000007)*n%1000000007;
	printf("%lld", ans);
	
}

  

原文地址:https://www.cnblogs.com/dongdong25800/p/9828213.html