Codeforces 114A-Cifera(暴力)
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 ...
随机推荐
- 1.MVC框架开发(初识MVC)
1.约定大于配置 Content:存放静态文件(样式表.静态图片等) Controllers:存放控制器类 Models:存放数据模型文件 Scripts:存放脚本文件 Views:存放视图文件,里面 ...
- C# 网页自动填表自动登录(转)
自动填表的方式有很多,关键是获取控件的id或者name. 比如源代码有 <input id="pwdInput" tabindex="2" class=& ...
- list和数组之间相互的转化
list变成数组: String[] str=(String[]) list.toArray(new String[list.size()]); 数组变成list: List<String> ...
- 通过本地加载ga.js文件提高Google Anlytics性能
Google Anlytics 分析代码是异步加载的,一般来讲不会影响网页性能,但是技术部的网页性能报告里老是提到ga.js的状态为Aborted,说明ga虽然是异步跟踪,但某些情况下对网页性能与加载 ...
- [原博客] BZOJ 1257 [CQOI2007] 余数之和
题目链接题意: 给定n,k,求 ∑(k mod i) {1<=i<=n} 其中 n,k<=10^9. 即 k mod 1 + k mod 2 + k mod 3 + … + k mo ...
- Stanford Parser学习入门(2)-命令行运行
在Stanford parser目录中已经定义了一部分命令行工具以及图形界面,本文将介绍如何在windows使用这些工具进行语法分析,Linux下也有shell可以使用. 关于如何搭建环境请参考上一篇 ...
- Linux ln命令 - 建立文件/目录链接
转自Linux ln命令 - 建立文件/目录链接 1. 使用方式:ln [option] source_file dist_file -f 建立时,将同档案名删 ...
- WAF
http://netsecurity.51cto.com/art/201010/231124.htm http://wenku.baidu.com/link?url=elrFtxPRcwJ5FjlXE ...
- 【BZOJ 2693】jzptab(莫比乌斯+分块)
2693: jzptab Description Input 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M Output T行 每行一个整数 表示第i组数据的结果 Sample I ...
- USB数据线上的“疙瘩”:原来有这么大用处!
在不少键盘.鼠标或是游戏外设的数据线末端我们都能见到一小段金属圆环.虽然这算得上是习以为常的一个设计,但如果说到其具体作用的话很多人一下子还真回答不上来.反正笔者在这里先可以告诉大家,这货肯定不是简简 ...