A Math Problem HDU 6182

本文参考自: 原文地址

A Math Problem
You are given a positive integer n, please count how many positive integers k satisfy kknkk≤n.

Input 

There are no more than 50 test cases.

Each case only contains a positivse integer n in a line.

1<=10^18


Output

 For each test case, output an integer indicates the number of positive integers k satisfy kknkk≤n in a line. Sample Input

1
4
Sample Output
1
2


题解:

我都不忍心说这题有什么算法,以你们最朴素的程序知识,枚举一个k,掰掰手指头就知道k<=15,然后根据题意算出k^k满足k^k<=n就行了。

如果非要将这题搞得复杂一点,也有如下几种解题方法:

1.打表,a[i]=i^i(i<=15),若n>=a[i-1] && n<a[i] 则k=i;

2.快速幂,个人感觉没有必要,除非秀算法,如果k是偶数 k^k=(k^(k/2))*(k^(k/2)) 

否则 k^k=(k^(k/2))*(k^(k/2))*k

#include<iostream>
#include<cmath>
using namespace std;
	
int main()
{
	unsigned long long m,n,k;
		
	while(cin>>n)
	{
		for(k=1;k<=15;++k)
		{
			m=k;
			for(int i=1;i<k;++i)
			{
				m*=k;	
			}
		
			if(m>n)	break;
		}
		cout<<k-1<<endl;	
	}
			
	return 0;	
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值