c题手写快速幂只能96%,改成pow()
调库能AC,不明白为什么手写过不了,球球热心的大佬帮忙看看
最开始以为是long long的问题,后来改成unsigned long long还是一样
QAQ
#include<bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
const ull M=1e18;
ull qpow(ull t, ull k)
{
ull res = 1;
while (k)
{
if (k&1) res = res * t ;
t = t * t;
k >>= 1;
}
return res;
}
int main() {
ios
ull cnt,ans,p,q;
cin>>p>>q;
cnt=1;
while(q<=M){
cnt++;
//ans=pow(p,q);可以过
ans=qpow(p,q);
if(ans==0)break;
p=q;
q=ans;
}
cout <<cnt<< endl;
return 0;
}
全部评论
(4) 回帖