kyopro_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub dyktr06/kyopro_library

:heavy_check_mark: lib/math/kth_root_integer.hpp

Verified with

Code

#pragma once

unsigned long long kthRoot(unsigned long long a, unsigned long long k){
    unsigned long long tmp = powl(a, (long double) 1 / (long double) k);
    unsigned long long res = 0;
    vector<unsigned long long> border = {tmp - 1, tmp, tmp + 1};
    for(auto x : border){
        if(x == 0) continue;
        unsigned long long curr = a;
        for(int i = 0; i < (int) k; i++){
            curr /= x;
        }
        if(curr >= 1) res = max(res, x);
    }
    return res;
}
#line 2 "lib/math/kth_root_integer.hpp"

unsigned long long kthRoot(unsigned long long a, unsigned long long k){
    unsigned long long tmp = powl(a, (long double) 1 / (long double) k);
    unsigned long long res = 0;
    vector<unsigned long long> border = {tmp - 1, tmp, tmp + 1};
    for(auto x : border){
        if(x == 0) continue;
        unsigned long long curr = a;
        for(int i = 0; i < (int) k; i++){
            curr /= x;
        }
        if(curr >= 1) res = max(res, x);
    }
    return res;
}
Back to top page