在此输入标题
2025-11-06 23:03:33
发布于:广东
5阅读
0回复
0点赞
pow有问题,可以手写快速幂,目前能想到的最快解法
#include <bits/stdc++.h>
using namespace std;
long long qpow(int a, int b){
if(b==1) return a;
if(b<=0) return 1;
long long ans = qpow(a, b/2);
ans *= ans;
if(b%2)
ans *= a;
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
long long n;
while(cin >> n)
cout << qpow(3, n)-1 << endl;
return 0;
}
这里空空如也





有帮助,赞一个