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
  1. 5
  2. 25
output
  1. YES
  2. 1
input
  1. 3
  2. 8
output
  1. NO
  1. Div2 A题。。
  2.  
  3. 没什么好说的。
  4.  
  5. 非常水
  1. 题意: k l,问l是否等于 k^n (n=1,2,3.....)注意:不要用pow()函数。。会有精度损失的
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <cmath>
  9. #include <stack>
  10. #define ll long long
  11. using namespace std;
  12. const int INF=0x3f3f3f3f;
  13. int l,k;
  14. ll my_pow(int a,int n)
  15. {
  16. 	ll ans=1;
  17. 	for(int i=1;i<=n;i++)
  18. 		ans*=a;
  19. 	return ans;
  20. }
  21. void solve()
  22. {
  23. 	if(k==l)
  24. 	{
  25. 		puts("YES");
  26. 		puts("0");
  27. 		return ;
  28. 	}
  29. 	int t=1,flag=0;
  30. 	while(1)
  31. 	{
  32. 		if(l==my_pow(k,t+1))
  33. 		{
  34. 			flag=1;
  35. 			break;
  36. 		}
  37. 		else if(l<my_pow(k,t+1))
  38. 		{
  39. 			break;
  40. 		}
  41. 		t++;
  42. 	}
  43. 	if(flag)
  44. 	{
  45. 		puts("YES");
  46. 		printf("%d\n",t);
  47. 	}
  48. 	else
  49. 	puts("NO");
  50. }
  51. int main()
  52. {
  53.     while(~scanf("%d%d",&k,&l))
  54. 		solve();
  55. 	return 0;
  56. }
  1.  

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. Linux下high CPU分析心得【非原创】

    非原创,搬运至此以作笔记, 原地址:http://www.cnitblog.com/houcy/archive/2012/11/28/86801.html 1.用top命令查看哪个进程占用CPU高ga ...

  2. MINA的session.close

    现象:客户端session.close之后,并没有提出,客户端程序一直hold在那里: 解决:调用了session.getService().dispose(false)方法后,客户端程序完成了退出 ...

  3. NET Portability Analyzer

    NET Portability Analyzer 分析迁移dotnet core 大多数开发人员更喜欢一次性编写好业务逻辑代码,以后再重用这些代码.与构建不同的应用以面向多个平台相比,这种方法更加容易 ...

  4. android studio中文乱码的解决方法【转】

    一. 在android的源文件中的乱码问题 Android Studio安装后发现所有的中文,不管是界面上的还是输出的log中的中文都变成小框框,具体的解决方法如下, 可以肯定是字体的问题 解决:菜单 ...

  5. Codeforces Round #316 div2

    一场充满血腥hack之战!!! Problem_A: 题意: n个候选人在m个城市进行投票,每个城市选出票数最多的一个候选人为城市候选人,如果票数相同,则取编号小的候选人. 再从这m个城市候选人中选出 ...

  6. Android使用SAX解析xml

    一.理论准备     SAX采用事件驱动机制来解析XML文档,每当SAX解析器发现文档开始.元素开始.文本.元素结束.文档结束等事件时,就会向外发送一次事件,而开发者则可以通过编写事件监听器处理这些事 ...

  7. [原博客] 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 ...

  8. 【网络流24题】 No.14 孤岛营救问题 (分层图最短路)

    [题意] 1944 年,特种兵麦克接到国防部的命令,要求立即赶赴太平洋上的一个孤岛, 营救被敌军俘虏的大兵瑞恩. 瑞恩被关押在一个迷宫里, 迷宫地形复杂, 但幸好麦克得到了迷宫的地形图. 迷宫的外形是 ...

  9. UVA 10048 Audiophobia 任意两点的路径上最大的边

    题目是要求任意给定两点的的路径上最大的边,最终输出这些最大边中最小的值,也就是求一条路径使得这条路径上最大的边在所有连通两点的路径中最短.根据Floyd—Warshall算法改造一下就行了.dp[i] ...

  10. FFmpeg发送流媒体的命令(UDP,RTP,RTMP)

    http://blog.csdn.net/leixiaohua1020/article/details/38283297