Submission #98972


Source Code Expand

#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>

using namespace std;

typedef long long LL;

const int MOD = 1000000007;

// x^n = x^(n-1) + ... x + 1
vector<LL>mulPoly(const vector<LL>&x, const vector<LL>&y) {
    int n=x.size();
    vector<LL>z(2*n);
    for (int i=0; i<n; i++) {
	for (int j=0; j<n; j++) {
	    z[i+j] = (z[i+j]+x[i]*y[j]) % MOD;
	}
    }
    for (int i=2*n-1; i>=n; i--) {
	for (int j=1; j<=n; j++) {
	    z[i-j] = (z[i-j]+z[i]) % MOD;
	}
    }
    z.resize(n);
    return z;
}
vector<LL>powPoly(vector<LL> x, LL y) {
    int n=x.size();
    vector<LL>r(n);
    r[0]=1;
    for (int i=0; (1LL<<i)<=y; i++) {
	if (y&(1LL<<i)) r = mulPoly(r, x);
	x = mulPoly(x, x);
    }
    return r;
}

int K, N;


int main() {
    scanf("%d %d", &K, &N);
    //K=1000; N=1000000000;
    
    if (N<=K) puts("1");
    else {
	vector<LL>x(K), r;
	x[1]=1;
	r = powPoly(x, N-1);
	LL ans=0;
	for (int i=0; i<K; i++) ans = (ans+r[i])%MOD;
	cout << ans << endl;
    }

    return 0;
}

Submission Info

Submission Time
Task T - フィボナッチ
User natsugiri
Language C++ (G++ 4.6.4)
Score 8
Code Size 1122 Byte
Status AC
Exec Time 467 ms
Memory 1060 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:47:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name All
Score / Max Score 8 / 8
Status
AC × 7
Set Name Test Cases
All 00, 01, 02, 03, 04, 90, 91
Case Name Status Exec Time Memory
00 AC 467 ms 1036 KB
01 AC 280 ms 1032 KB
02 AC 420 ms 1044 KB
03 AC 99 ms 1060 KB
04 AC 52 ms 1040 KB
90 AC 28 ms 1020 KB
91 AC 28 ms 1044 KB