2 seconds
256 megabytes
standard input
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 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.
The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).
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.
5
25
YES
1
3
8
NO
Div2 A题。。 没什么好说的。 非常水
题意: 给k l,问l是否等于 k^n (n=1,2,3.....)注意:不要用pow()函数。。会有精度损失的
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
int l,k;
ll my_pow(int a,int n)
{
ll ans=1;
for(int i=1;i<=n;i++)
ans*=a;
return ans;
}
void solve()
{
if(k==l)
{
puts("YES");
puts("0");
return ;
}
int t=1,flag=0;
while(1)
{
if(l==my_pow(k,t+1))
{
flag=1;
break;
}
else if(l<my_pow(k,t+1))
{
break;
}
t++;
}
if(flag)
{
puts("YES");
printf("%d\n",t);
}
else
puts("NO");
}
int main()
{ while(~scanf("%d%d",&k,&l))
solve();
return 0;
}
Codeforces 114A-Cifera(暴力)的更多相关文章
-
Karen and Game CodeForces - 816C (暴力+构造)
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...
-
Chladni Figure CodeForces - 1162D (暴力,真香啊~)
Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...
-
Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)
The only difference between easy and hard versions is a number of elements in the array. You are giv ...
-
CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
-
CodeForces - 589B(暴力)
题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...
-
CodeForces - 589B(暴力+排序)
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...
-
Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力
题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...
-
CodeForces 156A Message(暴力)
A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
-
Codeforces 479B. Towers 暴力
纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
-
<;读书笔记>;软件调试之道 :问题的核心-诊断
声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记. 不要急于动手! 尽管可以利用各种工具和技术以及软件自身查找缺陷,但是你最重要的财富是你的智 ...
-
JQ选择器逐一测试
在web开发中大部分时间都在查找DOM元素和对DOM元素进行控制. 从上面就知道JQ为什么那么流行,因为它极大的缩短对DOM元素的查找和控制,让开发更快. 而它的对查找DOM的方法也很方便,这归类为选 ...
-
[AngularJS] ui-router: named views
The ui-router library for AngularJS provides the ability to name views within your application. This ...
-
windows向ubuntu过渡之常用软件安装
好久没有写博客了,介于最近上操作系统实验课,好多同学装上了ubuntu,网上的教程比较杂乱,下面我就总结分享一些安装完ubuntu要安装的常用软件,会持续更新... 1.搜狗拼音安装 (1)在安装输入 ...
-
HIVE—索引、分区和分桶的区别
一.索引 简介 Hive支持索引,但是Hive的索引与关系型数据库中的索引并不相同,比如,Hive不支持主键或者外键. Hive索引可以建立在表中的某些列上,以提升一些操作的效率,例如减少MapRed ...
-
tkiner中Radiobutton单选框控件(七)
Radiobutton控件 由于本次内容中好多知识都是之前重复解释过的,本次就不做解释了.不太清楚的内容请参考tkinter1-6节中的内容 import tkinter wuya = tkinter ...
-
多继承下的super()指向的不一定是直接父类
常规情况 class Base: def __init__(self): print('Base.__init__') class A(Base): def __init__(self): super ...
-
LoadRunner-参数化(参数间关联)
多用户测试,每个用户账号对应一个密码,账号和密码需要一 一关联才能登录成功. 1.在已经对账号进行参数化后,选中密码的值->右键选择Replace with a Parameter,参数名为pa ...
-
SDOI 2017 天才黑客
/* 根据claris的 博客以及 beginend 的博客来写的 首先考虑如何求出最短路 可以从样例看出 路径是从边走到边的, 所以我们将边看作点 有共同端点的两边之间 互相连边, 边权为lcp. ...
-
4、构造方法、this、super
构造方法 构造方法引入 * A:构造方法的引入 在开发中经常需要在创建对象的同时明确对象的属性值,比如员工入职公司就要明确他的姓名.年龄等属性信息. 那么,创建对象就要明确属性值,那怎么解决呢?也就是 ...