#include<iostream>
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
long long qpow(long long a,long long n)
{
if(a==1)
return 1;
else if(a==0)
return 0;
else if(n==0)
return 1;
else if(n==1)
return a;
else if(n%2==0)
return qpow(a,n/2)*qpow(a,n/2);
else
return qpow(a,n/2)*qpow(a,n/2)*a;
}
int main()
{_
long long a,n;
int count=0;
while(cin>>a>>n)
{
count++;
if(a==0&&n==0)
{
cout<<"All Over. Exceeded "<<count<<" lines!\n";
break;
}
cout<<qpow(a,n)<<endl;
}
}
求解哪裡慢了,1跟0的次方特判都有寫啊
#include
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
long long qpow(long long a,long long n)
{
if(a==1)
return 1;
else if(a==0)
return 0;
else if(n==0)
return 1;
else if(n==1)
return a;
else if(n%2==0)
return qpow(a,n/2)*qpow(a,n/2);
else
return qpow(a,n/2)*qpow(a,n/2)*a;
}
int main()
{_
long long a,n;
int count=0;
while(cin>>a>>n)
{
count++;
if(a==0&&n==0)
{
cout<<"All Over. Exceeded "<<count<<" lines!\n";
break;
}
cout<<qpow(a,n)<<endl;
}
}求解哪裡慢了,1跟0的次方特判都有寫啊
-1