답안 #22467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22467 2017-04-30T04:54:17 Z oj.uz(#904, baekjoon, sgc109, plzrun) Fully Generate (KRIII5_FG) C++14
2 / 7
500 ms 197332 KB
#include <iostream>
using namespace std;
#define MAX 50000000
// #define MAX 50
const long long mod = 1000000007LL;
int a[MAX+1];
long long calc(long long a, long long b, long long c) {
    long long ans = 1;
    while (b > 0) {
        if (b % 2 == 1) {
            ans = (ans * a) % c;
        }
        a = (a*a) % c;
        b = b/2;
    }
    return ans;
}
int main(){
    long long n;
    cin >> n;
    a[1] = 1;
    a[2] = a[3] = 2;
    int now = 4;
    for (int i=3;; i++){
        for (int j=0; j<a[i]; j++) {
            a[now++] = i;
            if (now >= MAX) {
                break;
            }
        }
        if (now >= MAX) {
            break;
        }
    }
    if (n < MAX) {
        long long ans = 1;
        for (int i=2; i<=n; i++) {
            ans = (ans * a[i]) % mod;
        }
        cout << ans << '\n';
    } else {
        long long ans = 1;
        long long sum = 0;
        long long mul = 1;
        while (true) {
            if (sum == n) break;
            if (sum + a[ans] > n) {
                mul *= calc(ans, n-sum, mod);
                mul %= mod;
            } else {
                // cout << ans << ' ' << a[ans] << '\n';
                mul *= calc(ans, a[ans], mod);
                mul %= mod;
            }
            sum += a[ans];
            if (sum > n) {
                break;
            }
            ans++;
        }
        cout << mul << '\n';
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 197332 KB Output is correct
2 Correct 89 ms 197332 KB Output is correct
3 Correct 93 ms 197332 KB Output is correct
4 Correct 66 ms 197332 KB Output is correct
5 Correct 66 ms 197332 KB Output is correct
6 Correct 53 ms 197332 KB Output is correct
7 Correct 56 ms 197332 KB Output is correct
8 Correct 53 ms 197332 KB Output is correct
9 Correct 59 ms 197332 KB Output is correct
10 Correct 53 ms 197332 KB Output is correct
11 Correct 63 ms 197332 KB Output is correct
12 Correct 53 ms 197332 KB Output is correct
13 Correct 56 ms 197332 KB Output is correct
14 Correct 46 ms 197332 KB Output is correct
15 Correct 69 ms 197332 KB Output is correct
16 Correct 73 ms 197332 KB Output is correct
17 Correct 69 ms 197332 KB Output is correct
18 Correct 63 ms 197332 KB Output is correct
19 Correct 49 ms 197332 KB Output is correct
20 Correct 66 ms 197332 KB Output is correct
21 Correct 56 ms 197332 KB Output is correct
22 Correct 56 ms 197332 KB Output is correct
23 Correct 63 ms 197332 KB Output is correct
24 Correct 63 ms 197332 KB Output is correct
25 Correct 66 ms 197332 KB Output is correct
26 Correct 43 ms 197332 KB Output is correct
27 Correct 49 ms 197332 KB Output is correct
28 Correct 56 ms 197332 KB Output is correct
29 Correct 73 ms 197332 KB Output is correct
30 Correct 76 ms 197332 KB Output is correct
31 Correct 63 ms 197332 KB Output is correct
32 Correct 79 ms 197332 KB Output is correct
33 Correct 63 ms 197332 KB Output is correct
34 Correct 46 ms 197332 KB Output is correct
35 Correct 69 ms 197332 KB Output is correct
36 Correct 86 ms 197332 KB Output is correct
37 Correct 73 ms 197332 KB Output is correct
38 Correct 49 ms 197332 KB Output is correct
39 Correct 73 ms 197332 KB Output is correct
40 Correct 69 ms 197332 KB Output is correct
41 Correct 83 ms 197332 KB Output is correct
42 Correct 86 ms 197332 KB Output is correct
43 Correct 59 ms 197332 KB Output is correct
44 Correct 63 ms 197332 KB Output is correct
45 Correct 63 ms 197332 KB Output is correct
46 Correct 66 ms 197332 KB Output is correct
47 Correct 89 ms 197332 KB Output is correct
48 Correct 79 ms 197332 KB Output is correct
49 Correct 49 ms 197332 KB Output is correct
50 Correct 76 ms 197332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 197332 KB Output is correct
2 Correct 89 ms 197332 KB Output is correct
3 Correct 93 ms 197332 KB Output is correct
4 Correct 66 ms 197332 KB Output is correct
5 Correct 66 ms 197332 KB Output is correct
6 Correct 53 ms 197332 KB Output is correct
7 Correct 56 ms 197332 KB Output is correct
8 Correct 53 ms 197332 KB Output is correct
9 Correct 59 ms 197332 KB Output is correct
10 Correct 53 ms 197332 KB Output is correct
11 Correct 63 ms 197332 KB Output is correct
12 Correct 53 ms 197332 KB Output is correct
13 Correct 56 ms 197332 KB Output is correct
14 Correct 46 ms 197332 KB Output is correct
15 Correct 69 ms 197332 KB Output is correct
16 Correct 73 ms 197332 KB Output is correct
17 Correct 69 ms 197332 KB Output is correct
18 Correct 63 ms 197332 KB Output is correct
19 Correct 49 ms 197332 KB Output is correct
20 Correct 66 ms 197332 KB Output is correct
21 Correct 56 ms 197332 KB Output is correct
22 Correct 56 ms 197332 KB Output is correct
23 Correct 63 ms 197332 KB Output is correct
24 Correct 63 ms 197332 KB Output is correct
25 Correct 66 ms 197332 KB Output is correct
26 Correct 43 ms 197332 KB Output is correct
27 Correct 49 ms 197332 KB Output is correct
28 Correct 56 ms 197332 KB Output is correct
29 Correct 73 ms 197332 KB Output is correct
30 Correct 76 ms 197332 KB Output is correct
31 Correct 63 ms 197332 KB Output is correct
32 Correct 79 ms 197332 KB Output is correct
33 Correct 63 ms 197332 KB Output is correct
34 Correct 46 ms 197332 KB Output is correct
35 Correct 69 ms 197332 KB Output is correct
36 Correct 86 ms 197332 KB Output is correct
37 Correct 73 ms 197332 KB Output is correct
38 Correct 49 ms 197332 KB Output is correct
39 Correct 73 ms 197332 KB Output is correct
40 Correct 69 ms 197332 KB Output is correct
41 Correct 83 ms 197332 KB Output is correct
42 Correct 86 ms 197332 KB Output is correct
43 Correct 59 ms 197332 KB Output is correct
44 Correct 63 ms 197332 KB Output is correct
45 Correct 63 ms 197332 KB Output is correct
46 Correct 66 ms 197332 KB Output is correct
47 Correct 89 ms 197332 KB Output is correct
48 Correct 79 ms 197332 KB Output is correct
49 Correct 49 ms 197332 KB Output is correct
50 Correct 76 ms 197332 KB Output is correct
51 Execution timed out 500 ms 197332 KB Execution timed out
52 Halted 0 ms 0 KB -