ICPC2017南宁邀请赛1001&&HDU6182 A Math Problem

Problem Description

You are given a positive integer n, please count how many positive integers k satisfy kk≤n .

Input

There are no more than 50 test cases.
Each case only contains a positivse integer n in a line.
1≤n≤1018

Output

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

Sample Input

1

4

Sample Output

1

2

直接快速幂解决。。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll qpow(ll a, ll b) {
	ll ans = 1;
	ll k = a;
	while(b) {
		if(b&1) {
			ans = ans*k;
		}
		k = k*k;
		b >>= 1;
	}
	return ans;
}
int main() {
	ll n;
	while(scanf("%lld", &n) != EOF) {
		int sum = 0;
		for(int i = 1;i <= 15; i++) {
			if(qpow(i, i) <= n) {
				sum ++;
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Adusts/article/details/81699821
今日推荐