結果
| 問題 |
No.303 割れません
|
| ユーザー |
heno239
|
| 提出日時 | 2020-08-23 15:20:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 9,392 bytes |
| コンパイル時間 | 2,113 ms |
| コンパイル使用メモリ | 141,312 KB |
| 実行使用メモリ | 531,672 KB |
| 最終ジャッジ日時 | 2024-10-15 18:39:51 |
| 合計ジャッジ時間 | 13,656 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | MLE * 1 -- * 13 |
ソースコード
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
LDP operator*(const LDP& a, const LDP& b) {
return LDP{ a.first * b.first - a.second * b.second , a.first * b.second + a.second * b.first };
}
LDP operator+(const LDP& a, const LDP& b) {
return LDP{ a.first + b.first,a.second + b.second };
}
LDP operator-(const LDP& a, const LDP& b) {
return LDP{ a.first - b.first,a.second - b.second };
}
//非再帰
//eps=0.01を忘れずに
typedef vector<LDP> poly;
poly dft(poly f, bool inverse = false) {
int n = f.size(); int i, j, k;
//bit左右反転
for (i = 0, j = 1; j < n - 1; j++) {
for (k = n >> 1; k > (i ^= k); k >>= 1);
if (i > j)swap(f[i], f[j]);
}
for (int m = 2; m <= n; m *= 2) {
LDP zeta = { cos(2 * pi / (ld)m), sin(2 * pi / (ld)m) };
if (inverse) {
zeta = { cos(2 * pi * (m - 1) / (ld)m), sin(2 * pi * (m - 1) / (ld)m) };
}
for (i = 0; i < n; i += m) {
LDP powzeta = { 1,0 };
for (k = i; k < i + m / 2; k++) {
LDP t1 = f[k], t2 = powzeta * f[k + m / 2];
f[k] = t1 + t2; f[k + m / 2] = t1 - t2;
powzeta = powzeta * zeta;
}
}
}
if (inverse) {
for (i = 0; i < n; i++) {
f[i].first /= (ld)n;
f[i].second /= (ld)n;
}
}
return f;
}
poly multiply(poly g, poly h) {
int n = 1; int sz = g.size() + h.size();
while (n <= sz)n *= 2;
while (g.size() < n) {
g.push_back({ 0,0 });
}
while (h.size() < n) {
h.push_back({ 0,0 });
}
poly gg = dft(g);
poly hh = dft(h);
poly ff;
rep(i, n) {
ff.push_back(gg[i] * hh[i]);
}
return dft(ff, true);
}
const int base = 1000000;
struct bigint {
vector<int> s;
bigint() {};
bigint(ll n) {
if (n == 0)s.push_back(0);
while (n > 0) { s.push_back(n % base); n /= base; }
};
bigint(string t) { per(i, t.size())s.push_back(t[i]); };
friend std::ostream& operator<<(std::ostream& os, const bigint& x) {
if (x.s.size() == 1) {
os << x.s[0]; return os;
}
else {
string z;
rep(i, x.s.size()) {
string ad = to_string(x.s[x.s.size() - 1 - i]);
if (i > 0) {
while (ad.size() < 6)ad.insert(ad.begin(), '0');
}
z += ad;
}
os << z; return os;
}
}
};
bool operator==(const bigint& a, const bigint& b) { return a.s == b.s; };
bool operator==(const bigint& a, const int& b) { return a.s == bigint(b).s; };
bool operator!=(const bigint& a, const bigint& b) { return !(a == b); };
bool operator!=(const bigint& a, const int& b) { return a != to_string(b); };
bool operator<(const bigint& a, const bigint& b) {
if (a.s.size() != b.s.size())return a.s.size() < b.s.size();
per(i, a.s.size()) {
if (a.s[i] != b.s[i])return a.s[i] < b.s[i];
}
return false;
}
bool operator>(const bigint& a, const bigint& b) {
if (a.s.size() != b.s.size())return a.s.size() > b.s.size();
per(i, a.s.size()) {
if (a.s[i] != b.s[i])return a.s[i] > b.s[i];
}
return false;
}
bool operator>=(const bigint& a, const bigint& b) {
return !(a < b);
}
bool operator<=(const bigint& a, const bigint& b) {
return !(a > b);
}
bigint operator+(const bigint& a, const bigint& b) {
int c = 0;
int loc = 0;
int n = a.s.size(), m = b.s.size();
bigint ret;
ret.s.resize(max(n, m) + 1);
while (true) {
if (loc >= a.s.size() && loc >= b.s.size() && c == 0)break;
if (loc < a.s.size()) {
c += a.s[loc];
}
if (loc < b.s.size()) {
c += b.s[loc];
}
if (c >= base) {
ret.s[loc]=c - base;
c = 1;
}
else {
ret.s[loc] = c;
c = 0;
}
loc++;
}
while (ret.s.size() > 1 && ret.s.back() == 0)ret.s.pop_back();
return ret;
}
bigint operator+(const bigint& a, const int b) {
return a + bigint(b);
}
bigint operator-(const bigint& a, const bigint& b) {
int len = max(a.s.size(), b.s.size());
bigint ret; ret.s.resize(len); bool f = false;
int c = 0;
rep(i, len) {
if (i < a.s.size()) {
c += a.s[i];
}
if (i < b.s.size()) {
c -= b.s[i];
}
if (f) {
f = false;
c--;
}
if (c<0) {
f = true;
c += base;
}
ret.s[i] = c;
}
while (ret.s.size() > 1 && ret.s.back() == 0)ret.s.pop_back();
return ret;
}
bigint operator/(const bigint& a, const bigint& b) {
bigint ret(0);
bigint ans;
int len = a.s.size();
per(i, len) {
ret = ret + a.s[i];
int cnt = 0;
while (ret >= b)++cnt, ret = ret - b;
ans.s.push_back(cnt);
if (ret != 0)ret.s.push_back(0);
}
rep(i, ans.s.size()) {
if (ans.s[i] != 0) {
ans.s.erase(ans.s.begin(), ans.s.begin() + i);
break;
}
if (i == (int)ans.s.size() - 1) {
ans = 0;
}
}
reverse(all(ans.s));
return ans;
}
bigint operator%(const bigint& a, const bigint& b) {
bigint ret(0);
int len = a.s.size();
per(i, len) {
ret = ret + (a.s[i]);
while (ret >= b)ret = ret - b;
if (ret != 0 && i < len - 1)ret.s.push_back(0);
}
rep(i, ret.s.size()) {
if (ret.s[i] != 0 || i == ret.s.size() - 1) {
ret.s.erase(ret.s.begin(), ret.s.begin() + i);
break;
}
}
reverse(all(ret.s));
return ret;
}
bigint multi(const bigint& a, const int& t) {
bigint ret;
int c = 0;
rep(i, a.s.size()) {
c += (a.s[i]) * t;
ret.s.push_back(c % base);
c /= base;
}
while (c > 0) {
ret.s.push_back(c % base);
c /= base;
}
while (ret != 0 && ret.s.back() == 0)ret.s.pop_back();
return ret;
}
bigint operator*(const bigint& a, const bigint& b) {
poly p(a.s.size());
poly q(b.s.size());
rep(i, a.s.size()) {
p[i] = { a.s[i],0 };
}
rep(i, b.s.size()) {
q[i] = { b.s[i],0 };
}
poly r = multiply(p, q);
bigint res;
res.s.resize(r.size());
ll c = 0;
int loc = 0;
while (true) {
if (loc >= r.size() && c == 0)break;
if (loc < r.size())c += (r[loc].first + 0.01);
res.s[loc] = c % base;
c /= base;
loc++;
}
while (res.s.size() > 1 && res.s.back() == 0)res.s.pop_back();
return res;
}
bigint min(const bigint& a, const bigint& b) {
if (a < b)return a;
else return b;
}
bigint gcd(bigint a, bigint b) {
if (a < b)swap(a, b);
while (b > 0) {
bigint r = a % b; a = b; b = r;
}
return a;
}
typedef pair<bigint, bigint> bP;
typedef vector<vector<bigint>> mat;
typedef vector<bigint> vec;
mat mtmul(mat& A, mat& B) {
mat C(A.size(), vec(B[0].size()));
rep(i, (int)A.size()) {
rep(k, (int)B.size()) {
rep(j, (int)B[0].size()) {
C[i][j] = (C[i][j] + (A[i][k] * B[k][j]));
}
}
}
return C;
}
mat mtpow(mat A, ll n) {
mat B(A.size(), vec(A.size()));
rep(i, (int)A.size()) {
B[i][i] = 1;
}
while (n > 0) {
if (n & (ll)1)B = mtmul(B, A);
A = mtmul(A, A);
n >>= 1;
}
return B;
}
bigint dp[2];
bigint calc(ll n) {
mat A = { {1,1},{1,0} };
A = mtpow(A, n);
return A[0][1];
}
void solve() {
ll n; cin >> n;
if (n == 2) {
cout << "INF\n";
cout << 0 << "\n";
return;
}
bigint ans = calc(n);
bigint p = calc(n / 2);
if (n % 2 == 0)ans = ans - calc(n / 2) * calc(n / 2);
cout << n << "\n";
cout << ans<< "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(15);
//init_f();
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
heno239