답안 #22712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22712 2017-04-30T06:47:12 Z oj.uz(#904, baekjoon, sgc109, plzrun) Fully Generate (KRIII5_FG) C++11
2 / 7
453 ms 21552 KB
#include <iostream>
using namespace std;
#define MAX 5000000
// #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 {
                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 6 ms 21552 KB Output is correct
2 Correct 6 ms 21552 KB Output is correct
3 Correct 3 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 3 ms 21552 KB Output is correct
6 Correct 6 ms 21552 KB Output is correct
7 Correct 9 ms 21552 KB Output is correct
8 Correct 6 ms 21552 KB Output is correct
9 Correct 3 ms 21552 KB Output is correct
10 Correct 9 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 9 ms 21552 KB Output is correct
13 Correct 6 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 16 ms 21552 KB Output is correct
16 Correct 6 ms 21552 KB Output is correct
17 Correct 6 ms 21552 KB Output is correct
18 Correct 13 ms 21552 KB Output is correct
19 Correct 3 ms 21552 KB Output is correct
20 Correct 6 ms 21552 KB Output is correct
21 Correct 9 ms 21552 KB Output is correct
22 Correct 13 ms 21552 KB Output is correct
23 Correct 9 ms 21552 KB Output is correct
24 Correct 13 ms 21552 KB Output is correct
25 Correct 16 ms 21552 KB Output is correct
26 Correct 6 ms 21552 KB Output is correct
27 Correct 16 ms 21552 KB Output is correct
28 Correct 13 ms 21552 KB Output is correct
29 Correct 23 ms 21552 KB Output is correct
30 Correct 3 ms 21552 KB Output is correct
31 Correct 16 ms 21552 KB Output is correct
32 Correct 13 ms 21552 KB Output is correct
33 Correct 3 ms 21552 KB Output is correct
34 Correct 9 ms 21552 KB Output is correct
35 Correct 16 ms 21552 KB Output is correct
36 Correct 6 ms 21552 KB Output is correct
37 Correct 9 ms 21552 KB Output is correct
38 Correct 9 ms 21552 KB Output is correct
39 Correct 6 ms 21552 KB Output is correct
40 Correct 13 ms 21552 KB Output is correct
41 Correct 9 ms 21552 KB Output is correct
42 Correct 13 ms 21552 KB Output is correct
43 Correct 9 ms 21552 KB Output is correct
44 Correct 6 ms 21552 KB Output is correct
45 Correct 3 ms 21552 KB Output is correct
46 Correct 9 ms 21552 KB Output is correct
47 Correct 13 ms 21552 KB Output is correct
48 Correct 13 ms 21552 KB Output is correct
49 Correct 6 ms 21552 KB Output is correct
50 Correct 9 ms 21552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21552 KB Output is correct
2 Correct 6 ms 21552 KB Output is correct
3 Correct 3 ms 21552 KB Output is correct
4 Correct 3 ms 21552 KB Output is correct
5 Correct 3 ms 21552 KB Output is correct
6 Correct 6 ms 21552 KB Output is correct
7 Correct 9 ms 21552 KB Output is correct
8 Correct 6 ms 21552 KB Output is correct
9 Correct 3 ms 21552 KB Output is correct
10 Correct 9 ms 21552 KB Output is correct
11 Correct 0 ms 21552 KB Output is correct
12 Correct 9 ms 21552 KB Output is correct
13 Correct 6 ms 21552 KB Output is correct
14 Correct 0 ms 21552 KB Output is correct
15 Correct 16 ms 21552 KB Output is correct
16 Correct 6 ms 21552 KB Output is correct
17 Correct 6 ms 21552 KB Output is correct
18 Correct 13 ms 21552 KB Output is correct
19 Correct 3 ms 21552 KB Output is correct
20 Correct 6 ms 21552 KB Output is correct
21 Correct 9 ms 21552 KB Output is correct
22 Correct 13 ms 21552 KB Output is correct
23 Correct 9 ms 21552 KB Output is correct
24 Correct 13 ms 21552 KB Output is correct
25 Correct 16 ms 21552 KB Output is correct
26 Correct 6 ms 21552 KB Output is correct
27 Correct 16 ms 21552 KB Output is correct
28 Correct 13 ms 21552 KB Output is correct
29 Correct 23 ms 21552 KB Output is correct
30 Correct 3 ms 21552 KB Output is correct
31 Correct 16 ms 21552 KB Output is correct
32 Correct 13 ms 21552 KB Output is correct
33 Correct 3 ms 21552 KB Output is correct
34 Correct 9 ms 21552 KB Output is correct
35 Correct 16 ms 21552 KB Output is correct
36 Correct 6 ms 21552 KB Output is correct
37 Correct 9 ms 21552 KB Output is correct
38 Correct 9 ms 21552 KB Output is correct
39 Correct 6 ms 21552 KB Output is correct
40 Correct 13 ms 21552 KB Output is correct
41 Correct 9 ms 21552 KB Output is correct
42 Correct 13 ms 21552 KB Output is correct
43 Correct 9 ms 21552 KB Output is correct
44 Correct 6 ms 21552 KB Output is correct
45 Correct 3 ms 21552 KB Output is correct
46 Correct 9 ms 21552 KB Output is correct
47 Correct 13 ms 21552 KB Output is correct
48 Correct 13 ms 21552 KB Output is correct
49 Correct 6 ms 21552 KB Output is correct
50 Correct 9 ms 21552 KB Output is correct
51 Runtime error 453 ms 21552 KB Execution killed with signal 11 (could be triggered by violating memory limits)
52 Halted 0 ms 0 KB -