hiho week 41 register

Ended

Participants:3476

Verdict:Accepted
Score:100 / 100
Submitted:2015-04-13 23:15:33

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
#include <map>
using namespace std;
map<int, int> m;
const int md = 19999997;
long long f(const int x) {
    if(x <= 2) return x ? 1 : 0;
    if(m.count(x)) return m[x];
    const int k = x >> 1;
    const long long a = f(k);
    const long long b = f(k + 1);
    if(x & 1) return m[x] = (a * a + b * b) % md;
    else return m[x] = a * (b + b - a + md) % md;
}
int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", int(f(n + 1)));
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX