HDU 6182 A Math Problem 水题

本文提供了一道 HDU 6182 的解题思路及代码实现,通过快速幂运算求解 k^k<=N 的 k 的数量,并分享了解题过程中的思考。

  题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6182

  题目描述: 输入N, 输出满足k^k <= N 的 k的个数

  解题思路: 水水更健康

  代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iterator>
#include <cmath>
#include <algorithm>
#include <stack>
#include <deque>
#include <map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define mem0(a) memset(a,0,sizeof(a))
#define sca(x) scanf("%d",&x)
#define de printf("=======\n")
typedef long long ll;
using namespace std;

ll n;
ll a[20];

ll qpower( ll a, ll b ) {
    ll res = 1;
    while( b ) {
        if( b & 1 ) res = res * a;
        b >>= 1;
        a = a * a;
    }
    return res;
}

void init() {
    for( int i = 1; i <= 15; i++ ) {
        a[i] = qpower(i, i);
    }
//    for( int i = 1; i <= 15; i++ ) {
//        cout << a[i] << " ";
//    }
//    cout << endl;
}
int main() {
    init();
    while( cin >> n ) {
        int i=0;
        for( i = 1; i <= 15; i++ ) {
//            cout << n << " " << a[i] << endl;
            if( n < a[i] ) break;
        }
        if( i == 16 && n == 437893890380859375 ) {
            cout << 15 << endl;
        }
        else if( i == 16 ) {
            cout << 15 << endl;
        }
        else {
            cout << i-1 << endl;
        }
    }
}
View Code

  思考: 好水啊....我写这题还花了一些时间......自己中间一段时间还把自己搞糊涂了.....是真的菜

转载于:https://www.cnblogs.com/FriskyPuppy/p/7461100.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值