注意到一个数字x必然会被唯一表示成a2×b的形式.其中∣μ(b)∣=1。
所以这个式子会把[1,nk]的每个整数恰好算一次.
所以答案就是nk,快速幂即可.
时间复杂度O(logk).
//
// main.cpp
// RXD and math
//
// Created by wenhan on 2017/8/7.
// Copyright © 2017年 wenhan. All rights reserved.
//
#include <iostream>
#include <cstdio>
using namespace std;
const long long mmax=1e9+7;
int main() {
long long n,k;
int count=1;
while (scanf("%lld%lld",&n,&k)!=EOF) {
long long s=1;
while (k) {
if(k%2==1)
{
s=((s%mmax)*(n%mmax))%mmax;
k--;
}
n=((n%mmax)*(n%mmax))%mmax;
k=k/2;
}
printf("Case #%d: %lld\n",count++,s%mmax);
}
// insert code here...
//std::cout << "Hello, World!\n";
return 0;
}