Submission #19448386


Source Code Expand

Copy
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)

const ll INF = 1000000000000; //10^12:∞
const ll MOD = 1000000007; //10^9+7:合同式の法

vector<pair<ll, ll>> primeFactorization(ll N) {
    static vector<bool> isPrime(1100000, true);
    isPrime.at(0) = false;
    isPrime.at(1) = false;

    vector<pair<ll, ll>> res;
    ll limit = sqrt(N);
    for(ll i = 2; i <= limit; i++) {
        /* エラトステネスの篩 */
        if(!isPrime.at(i)) {
            continue;
        }

        for(ll j = 2; i * j <= limit; j++) {
            isPrime.at(i * j) = false;
        }
        /* ここまで */

        ll count = 0;
        while(N % i == 0) {
            N /= i;
            count++;
        }

        if(count > 0) {
            res.push_back({i, count});
        }
    }

    if(N != 1) {
        res.push_back({N, 1});
    }

    return res;
}

int main(){
    ll N, P;
    cin >> N >> P;
    vector<pair<ll, ll>> vec = primeFactorization(P);
    ll ans = 1;
    for(const pair<ll, ll> &elm : vec) {
        ll count = elm.second;
        for(ll i = 0; i < count / N; i++) {
            ans *= elm.first;
        }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task C - Product and GCD
User kabuto64425
Language C++ (GCC 9.2.1)
Score 300
Code Size 1487 Byte
Status AC
Exec Time 19 ms
Memory 3712 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 34
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt, sample4.txt
All sample1.txt, sample2.txt, sample3.txt, sample4.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt
Case Name Status Exec Time Memory
1.txt AC 11 ms 3480 KB
10.txt AC 6 ms 3424 KB
11.txt AC 10 ms 3600 KB
12.txt AC 12 ms 3492 KB
13.txt AC 13 ms 3424 KB
14.txt AC 14 ms 3544 KB
15.txt AC 8 ms 3580 KB
16.txt AC 15 ms 3468 KB
17.txt AC 15 ms 3592 KB
18.txt AC 12 ms 3576 KB
19.txt AC 14 ms 3580 KB
2.txt AC 12 ms 3580 KB
20.txt AC 15 ms 3496 KB
21.txt AC 5 ms 3472 KB
22.txt AC 9 ms 3420 KB
23.txt AC 15 ms 3544 KB
24.txt AC 2 ms 3472 KB
25.txt AC 13 ms 3488 KB
26.txt AC 16 ms 3416 KB
3.txt AC 14 ms 3600 KB
4.txt AC 10 ms 3484 KB
5.txt AC 19 ms 3580 KB
6.txt AC 13 ms 3420 KB
7.txt AC 12 ms 3420 KB
8.txt AC 15 ms 3712 KB
9.txt AC 14 ms 3544 KB
sample1.txt AC 3 ms 3472 KB
sample2.txt AC 7 ms 3472 KB
sample3.txt AC 2 ms 3544 KB
sample4.txt AC 15 ms 3488 KB