O(logn)慢过O(n)(违规自删)
  • 板块灌水区
  • 楼主ywtank
  • 当前回复9
  • 已保存回复9
  • 发布时间2024/9/11 13:23
  • 上次更新2024/9/11 19:43:34
查看原帖
O(logn)慢过O(n)(违规自删)
1070431
ywtank楼主2024/9/11 13:23

这是我认为低复杂度的代码

#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,帮助文档看不懂一点)

希望大佬帮忙看看

2024/9/11 13:23
加载中...