Codeforces 114A-Cifera

Codeforce原题链接

题目:

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值