pow我自己寫一個
內建的pow在5的3次方會莫名其妙出錯...
#include <bits/stdc++.h>
using namespace std;
int fun1(int input)
{
int count=0;
while(input!=0)
{
input/=10;
++count;
}
return count;
}
int power(int base,int n)
{
int sum=1;
for(int i=0;i<n;++i)
sum*=base;
return sum;
}
int fun2(int input,int count,int base)
{
int k=power(10,count-1),sum=0,temp=count;
for(int i=0;i<temp;++i)
{
sum+=input/k*power(base,count-1);
input%=k;
k/=10;
--count;
}
return sum;
}
int main()
{
int a,b,count,dec=0;
cin>>a>>b;
count=fun1(b);
dec=fun2(b,count,a);
int k=power(10,count-1),sum=0;
for(int i=0;i<count;++i)
{
sum+=power(b/k,count);
b%=k;
k/=10;
}
if(sum==dec)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}