【简单演算】#86 A. Cifera

本文介绍了一个趣味数学挑战——Petya发明了一种表示数字的方式:使用la的数量来表示数字的重要程度。文章详细解释了如何判断一个数字是否属于这种表示方式,并提供了一个简单的算法实现。

A. Cifera
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 k2petricium 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.

Input

The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).

Output

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.

Sample test(s)
input
5
25
output
YES
1
input
3
8
output
NO

说是在某种语言里,一个数的平方叫做 xxx la xxx,立方是 xxx la xxx la xxx,也就是n次方就是n-1个la,给两个数,问第二个数是第一个数的某个次幂吗?是的话,表示出来有几个la呢?

那我们就 

while(tmp<l) { tmp*=k; cnt++; } 

这样一下~ 然后cnt就能说明一切啦~ 啊需要注意的是,超过范围但是发现不是某次幂要记得判断哦~

#include <cstdio>
#include <string>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
// http://codeforces.com/contest/114
// Cifera
int main()
{
	int cnt=0;
	ll k,tmp,l;	cin>>k>>l; tmp=k;
	while(tmp<l)
	{
		tmp*=k;
		cnt++;
	} 
	if(tmp==l)cout<<"YES"<<endl<<cnt;
	else cout<<"NO";
	return 0;
} 





评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值