题目:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word “tma” (which now means “too much to be counted”) used to stand for a thousand and “tma tmyschaya” (which literally means “the tma of tmas”) used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number’s importance is the number of articles la in its title.
Petya’s invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
翻译一下这个题的意思就是输入两个数字,让你判断第二个数是不是第一个数的次方数,不是的话输出"NO"。如果是,就输出"YES"和这个次方数的重要性(就是这个数是另一个数的几次方,然后减去1。比如8是2的三次方,那么就是2)。
这题挺简单的,但是有一点要注意,变量要开成long long。
下面是AC代码:
#include<iostream>
using namespace std;
int main()
{
long long k, l;
cin >> k >> l;
long long n;
int cnt = 0;
n = k;
while (1)
{
if (n > l)
{
cout << "NO";
break;
}
else if (n == l)
{
cout << "YES"<<endl<<cnt;
break;
}
n *= k;
cnt++;
}
return 0;
}