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 ...
随机推荐
- PHP程序的一次重构记录
项目和新需求: 我们有一个PHP写的webmail系统,有一个mail_list.php用于展现用户的邮件列表这个页面支持folderId参数(因为邮件是存在不同的文件夹下的)由于邮件太多所以支持翻页 ...
- Word添加带圈文字
这个在项目有编号李没有,只能一个一个输入 A.开始------------字体里选择带圈的字符号 B.插入,符号里选编号
- 破解之关键CALL与关键跳查找方法
找关键CALL和关键跳 方法一: 输入假码注册程序,记录下错误提示信息. OD载入程序--> 右键-->查找-->所有参考文本字串-->(右键-->查找文本,注:不要区分 ...
- hdu 1116
欧拉回路,利用并查集来实现: 代码: #include<cstdio> #include<cstring> #include<vector> using names ...
- 带你了解世界最先进的手势识别技术 -- 微软,凌感,Leap...
转载 今天为大家解释一下现有的几种主要的手势识别技术,为你揭开手势识别技术的神秘面纱. 概述 谈起手势识别技术,由简单粗略的到复杂精细的,大致可以分为三个等级:二维手型识别.二维手势识别.三维手势识别 ...
- Https 原理
HTTPS其实是有两部分组成:HTTP + SSL / TLS, 也就是在HTTP上又加了一层处理加密信息的模块.服务端和客户端的信息传输都会通过TLS进行加密,所以传输的数据都是加密后的数据 1. ...
- 使用vs自带的wcf配置工具
服务和行为是并列的 对应到配置文件中 wcf的配置在system.serviceModel中 可以有多个服务 一个服务会有一个主机以及多个终结点 主机包含多个基址 baseAddress 终结点,由 ...
- Datetime中yyyy-MM-dd-hh-mm-ss的格式
namespace yyyy_MM_dd_hh_mm{ class Program { static void Main(string[] args) { wh ...
- POJ_2100_Graveyard_Design_(尺取法)
描述 http://poj.org/problem?id=2100 求连续平方和=n的序列个数,并输出序列. Graveyard Design Time Limit: 10000MS Memory ...
- JAVA vo pojo javabean dto的区别
JavaBean 是一种JAVA语言写成的可重用组件.为写成JavaBean,类必须是具体的和公共的,并且具有无参数的构造器.JavaBean 通过提供符合一致性设计模式的公共方法将内部域暴露成员属性 ...