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

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
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(暴力)的更多相关文章

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

  2. Chladni Figure CodeForces - 1162D (暴力,真香啊~)

    Chladni Figure CodeForces - 1162D Inaka has a disc, the circumference of which is nn units. The circ ...

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

  4. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  5. CodeForces - 589B(暴力)

    题目链接:http://codeforces.com/problemset/problem/589/B 题目大意:告诉你n 个矩形,知道矩形的长度和宽度(长和宽可以互换),每个矩形的长度可以剪掉一部分 ...

  6. CodeForces - 589B(暴力+排序)

    Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n ...

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

  8. CodeForces 156A Message(暴力)

    A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  9. Codeforces 479B. Towers 暴力

    纯暴力..... B. Towers time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. Morgan stanley 电话面试

    首先是聊项目, 不会涉及到具体的技术问题 1.C和C++的区别:C++里的RTTI 2.vector 和 list的区别 : casting operator ; smart pointer. 3.数 ...

  2. bzoj 3435: [Wc2014]紫荆花之恋 替罪羊树维护点分治 && AC400

    3435: [Wc2014]紫荆花之恋 Time Limit: 240 Sec  Memory Limit: 512 MBSubmit: 159  Solved: 40[Submit][Status] ...

  3. Dirichlet Process 和 Dirichlet Process Mixture模型

    Dirichlet Process 和 Dirichlet Process Mixture模型 [本文链接:http://www.cnblogs.com/breezedeus/archive/2012 ...

  4. 安装ECMall后报PHP Strict Standards错误,请问如何解决

    Strict Standards: Non-static method ECMall::startup() should not be called statically in /htdocs/ecm ...

  5. SQL Server GOTO使用实例详解

    GOTO命令用来改变程序执行的流程,使程序跳到标识符指定的程序行再继续往下执行.语法:GOTO  标识符标识符需要在其名称后加上一个冒号“:”.例如:“33:”,“loving:.SQL语句如下:DE ...

  6. 【HDOJ】2732 Leapin' Lizards

    贪心+网络流.对于每个结点,构建入点和出点.对于每一个lizard>0,构建边s->in position of lizard, 容量为1.对于pillar>0, 构建边in pos ...

  7. bzoj1231

    看到n<=16不难想到状压dp 我们用二进制表示前x个位置,哪些牛被已经被选过了 这里我们可以通过穷举二进制数的顺序来转移 所以二维就够了 ..] of longint;     f:.. sh ...

  8. Linux kernel 内存损坏漏洞

    漏洞名称: Linux kernel 内存损坏漏洞 CNNVD编号: CNNVD-201310-143 发布时间: 2013-10-11 更新时间: 2013-10-11 危害等级: 中危   漏洞类 ...

  9. oracle 绑定变量

    “绑定变量”这个词也许对于某些人来说看以来陌生,其实我们在很早的时候就已经开始运用它了. 在java中使用的PrepareStatement对象,大家一定会说这不是将sql语句做预编译操作嘛,被封装的 ...

  10. C#入门经典学习笔记一

    这篇主要讲C#的一些语法. 1.委托 委托类型声明的格式如下: public delegate void TestDelegate(string message); delegate 关键字用于声明一 ...