Submission #22708

# Submission time Handle Problem Language Result Execution time Memory
22708 2017-04-30T06:46:09 Z oj.uz(#904, baekjoon, sgc109, plzrun) Fully Generate (KRIII5_FG) C++11
2 / 7
500 ms 41080 KB
#include <iostream>
using namespace std;
#define MAX 10000000
// #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;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 41080 KB Output is correct
2 Correct 13 ms 41080 KB Output is correct
3 Correct 13 ms 41080 KB Output is correct
4 Correct 9 ms 41080 KB Output is correct
5 Correct 6 ms 41080 KB Output is correct
6 Correct 9 ms 41080 KB Output is correct
7 Correct 6 ms 41080 KB Output is correct
8 Correct 23 ms 41080 KB Output is correct
9 Correct 3 ms 41080 KB Output is correct
10 Correct 13 ms 41080 KB Output is correct
11 Correct 16 ms 41080 KB Output is correct
12 Correct 19 ms 41080 KB Output is correct
13 Correct 19 ms 41080 KB Output is correct
14 Correct 13 ms 41080 KB Output is correct
15 Correct 19 ms 41080 KB Output is correct
16 Correct 16 ms 41080 KB Output is correct
17 Correct 16 ms 41080 KB Output is correct
18 Correct 13 ms 41080 KB Output is correct
19 Correct 13 ms 41080 KB Output is correct
20 Correct 0 ms 41080 KB Output is correct
21 Correct 19 ms 41080 KB Output is correct
22 Correct 16 ms 41080 KB Output is correct
23 Correct 13 ms 41080 KB Output is correct
24 Correct 16 ms 41080 KB Output is correct
25 Correct 16 ms 41080 KB Output is correct
26 Correct 19 ms 41080 KB Output is correct
27 Correct 26 ms 41080 KB Output is correct
28 Correct 6 ms 41080 KB Output is correct
29 Correct 13 ms 41080 KB Output is correct
30 Correct 16 ms 41080 KB Output is correct
31 Correct 3 ms 41080 KB Output is correct
32 Correct 6 ms 41080 KB Output is correct
33 Correct 19 ms 41080 KB Output is correct
34 Correct 19 ms 41080 KB Output is correct
35 Correct 19 ms 41080 KB Output is correct
36 Correct 16 ms 41080 KB Output is correct
37 Correct 9 ms 41080 KB Output is correct
38 Correct 16 ms 41080 KB Output is correct
39 Correct 29 ms 41080 KB Output is correct
40 Correct 3 ms 41080 KB Output is correct
41 Correct 9 ms 41080 KB Output is correct
42 Correct 16 ms 41080 KB Output is correct
43 Correct 16 ms 41080 KB Output is correct
44 Correct 19 ms 41080 KB Output is correct
45 Correct 19 ms 41080 KB Output is correct
46 Correct 19 ms 41080 KB Output is correct
47 Correct 19 ms 41080 KB Output is correct
48 Correct 19 ms 41080 KB Output is correct
49 Correct 26 ms 41080 KB Output is correct
50 Correct 19 ms 41080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 41080 KB Output is correct
2 Correct 13 ms 41080 KB Output is correct
3 Correct 13 ms 41080 KB Output is correct
4 Correct 9 ms 41080 KB Output is correct
5 Correct 6 ms 41080 KB Output is correct
6 Correct 9 ms 41080 KB Output is correct
7 Correct 6 ms 41080 KB Output is correct
8 Correct 23 ms 41080 KB Output is correct
9 Correct 3 ms 41080 KB Output is correct
10 Correct 13 ms 41080 KB Output is correct
11 Correct 16 ms 41080 KB Output is correct
12 Correct 19 ms 41080 KB Output is correct
13 Correct 19 ms 41080 KB Output is correct
14 Correct 13 ms 41080 KB Output is correct
15 Correct 19 ms 41080 KB Output is correct
16 Correct 16 ms 41080 KB Output is correct
17 Correct 16 ms 41080 KB Output is correct
18 Correct 13 ms 41080 KB Output is correct
19 Correct 13 ms 41080 KB Output is correct
20 Correct 0 ms 41080 KB Output is correct
21 Correct 19 ms 41080 KB Output is correct
22 Correct 16 ms 41080 KB Output is correct
23 Correct 13 ms 41080 KB Output is correct
24 Correct 16 ms 41080 KB Output is correct
25 Correct 16 ms 41080 KB Output is correct
26 Correct 19 ms 41080 KB Output is correct
27 Correct 26 ms 41080 KB Output is correct
28 Correct 6 ms 41080 KB Output is correct
29 Correct 13 ms 41080 KB Output is correct
30 Correct 16 ms 41080 KB Output is correct
31 Correct 3 ms 41080 KB Output is correct
32 Correct 6 ms 41080 KB Output is correct
33 Correct 19 ms 41080 KB Output is correct
34 Correct 19 ms 41080 KB Output is correct
35 Correct 19 ms 41080 KB Output is correct
36 Correct 16 ms 41080 KB Output is correct
37 Correct 9 ms 41080 KB Output is correct
38 Correct 16 ms 41080 KB Output is correct
39 Correct 29 ms 41080 KB Output is correct
40 Correct 3 ms 41080 KB Output is correct
41 Correct 9 ms 41080 KB Output is correct
42 Correct 16 ms 41080 KB Output is correct
43 Correct 16 ms 41080 KB Output is correct
44 Correct 19 ms 41080 KB Output is correct
45 Correct 19 ms 41080 KB Output is correct
46 Correct 19 ms 41080 KB Output is correct
47 Correct 19 ms 41080 KB Output is correct
48 Correct 19 ms 41080 KB Output is correct
49 Correct 26 ms 41080 KB Output is correct
50 Correct 19 ms 41080 KB Output is correct
51 Execution timed out 500 ms 41080 KB Execution timed out
52 Halted 0 ms 0 KB -