結果
問題 | No.8038 フィボナッチ数列の周期 |
ユーザー |
![]() |
提出日時 | 2018-04-02 01:35:33 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,345 bytes |
コンパイル時間 | 992 ms |
コンパイル使用メモリ | 92,044 KB |
実行使用メモリ | 13,888 KB |
最終ジャッジ日時 | 2024-06-26 06:27:16 |
合計ジャッジ時間 | 7,415 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 TLE * 1 -- * 8 |
コンパイルメッセージ
main.cpp: In function ‘long long int solve(long long int)’: main.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type] 34 | } | ^
ソースコード
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <string> #include <iomanip> #include <algorithm> #include <cmath> #include <stdio.h> using namespace std; #define int long long int MOD = 1000000007; int p(int a, int b) { if (b == 0)return 1; if (b % 2 == 0) { return p((a*a) % MOD, b / 2); } else { return (p((a*a) % MOD, b / 2) * a) % MOD; } } int inv(int a) { return p(a, MOD - 2); } long long solve(long long m) { long long a = 0, b = 1, c = a + b; for (int i = 0; i < m * m; i++) { c = (a + b) % m; a = b; b = c; if (a == 0 && b == 1) return i + 1; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> pr(N); vector<int> k(N); int res = 1; vector<int> x; map<int, int> mp; for (int i = 0; i < N; i++) { cin >> pr[i] >> k[i]; map<int, int> tmp; tmp[pr[i]] = k[i] - 1; int x = solve(pr[i]); //cerr << "x=" << x << endl; for (int j = 2; j <= x; j++) { if (j*j > x)j = x; while (x%j == 0) { x /= j; tmp[j]++; } } if (x != 1)cerr << "ERROR x=" << x << endl; for (auto m : tmp) { mp[m.first] = max(mp[m.first], m.second); //mp[m.first] += m.second; } } for (auto m : mp) { //cerr << m.first << " " << m.second << endl; res = (res*p(m.first, m.second)) % MOD; } cout << res << endl; }