这是我认为低复杂度的代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long k(unsigned long long n,unsigned long long x){
if(x==1)return n;
return k(n,(x>>1))*k(n,((x+1)>>1));
}
int main(){
freopen("D:\\王皓宁C\\快速幂测试.txt","r",stdin);
int x,y;
cin >> x >> y;
cout << k(x,y);
return 0;
}
这是我认为高复杂度的代码
#include <bits/stdc++.h>
using namespace std;
unsigned long long k(unsigned long long n,unsigned long long x){
if(x==1)return n;
return k(n,x-1)*n;
}
int main(){
//system("D:\\王皓宁Tython程序\\快速幂测试.py");
freopen("D:\\王皓宁C\\快速幂测试.txt","r",stdin);
int x,y;
cin >> x >> y;
cout << k(x,y);
return 0;
}
实测rt(萌新不会用Latex打时间复杂度,请原谅OWQ,帮助文档看不懂一点)
希望大佬帮忙看看