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 ...
 
随机推荐
- 一个简单的makefile,一次性编译本文件夹下所有的cpp文件
			
代码: CXX := g++ CFLAGS := -g TARGET := xxx.exe SRCS := $(wildcard *.cpp) OBJS := $(patsubst %cpp,%o,$ ...
 - iOS 常用基础框架
			
框架名称 功能 Foundation 提供OC的基础类(像NSObject).基本数据类型等 UIKit 创建和管理应用程序的用户界面 QuartzCore 提供动画特效以及通过硬件进行渲染的能力 C ...
 - Creating Shazam in Java
			
A couple of days ago I encountered this article: How Shazam Works This got me interested in how a pr ...
 - socket.io
			
http://www.cnblogs.com/fullhouse/archive/2011/07/18/2109936.html http://www.cnblogs.com/fullhouse/ar ...
 - Code First:如何实现一个主类中包含多个复类
			
假设我们在程序中要用到的类的结构是这样的,这里比较特别的是B在A中出现了最少两次 public class B { [Key] public int Id { get; set; } public s ...
 - 网站页面优化必然趋势—WebP  图片!
			
本文梗概:众所周知,浏览器可以通过 HTTP 请求的 Accpet 属性 来指定接收的内容类型.依靠这个技术,可以在不修改任何 HTML/CSS 或者图片的情况下,向浏览器提供优化的图片,从而降低带宽 ...
 - JQuery 去除字符串两边多余的空格
			
var str = " hello "; str = $.trim(str);//去除多余空格 //变成了"hello"
 - SPRING IN ACTION 第4版笔记-第二章Wiring Beans-005-<constructor-arg>和c-namespace
			
1. package soundsystem; public class SgtPeppers implements CompactDisc { private String title = &quo ...
 - 测试用(编写优质嵌入式C程序)
			
注:相比于Word,如果使用CSDN自带编辑器写出结构清晰的文档,需要花费更多的时间,所以我尝试将我写的一些word文档转换为图片发布,这样就可以保持原来的结构.字体,可以获得更好的可读性.图片的分辨 ...
 - eclipse或IDEA连接魅蓝
			
1.首先 安装ADB 驱动 http://developer.android.com/tools/device.html 如果没装就自行去下载安装 别的品牌都可以顺利连接,魅族手机特有的原因导至在开发 ...