結果
| 問題 |
No.3353 リウヴィルの定数計算
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2025-11-14 21:24:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,611 bytes |
| コンパイル時間 | 4,945 ms |
| コンパイル使用メモリ | 333,952 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-11-14 21:24:23 |
| 合計ジャッジ時間 | 5,713 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
struct fraction {
/**
* p/q を表す分数型
* 常に gcd(p,q)==1 かつ q>0 を保つ
*/
using i128 = __int128_t;
long long p, q;
fraction(long long P = 0, long long Q = 1) : p(P), q(Q) {
if (Q == 0) throw std::invalid_argument("Denominator cannot be zero");
normalize();
}
void normalize() {
if (q < 0) p = -p, q = -q;
long long g = std::gcd(std::abs(p), q);
if (g) p /= g, q /= g;
}
friend bool operator<(const fraction &a, const fraction &b) {
return i128(a.p) * b.q < i128(b.p) * a.q;
}
friend bool operator==(const fraction &a, const fraction &b) {
return a.p == b.p && a.q == b.q;
}
friend bool operator!=(const fraction &a, const fraction &b) {
return !(a == b);
}
friend bool operator>(const fraction &a, const fraction &b) {
return b < a;
}
friend bool operator<=(const fraction &a, const fraction &b) {
return !(b < a);
}
friend bool operator>=(const fraction &a, const fraction &b) {
return !(a < b);
}
friend fraction operator+(fraction a, const fraction &b) {
a += b;
return a;
}
friend fraction operator-(fraction a, const fraction &b) {
a -= b;
return a;
}
friend fraction operator*(fraction a, const fraction &b) {
a *= b;
return a;
}
friend fraction operator/(fraction a, const fraction &b) {
a /= b;
return a;
}
fraction &operator+=(const fraction &other) {
i128 num = i128(p) * other.q + i128(other.p) * q;
i128 den = i128(q) * other.q;
p = static_cast<long long>(num);
q = static_cast<long long>(den);
normalize();
return *this;
}
fraction &operator-=(const fraction &other) {
i128 num = i128(p) * other.q - i128(other.p) * q;
i128 den = i128(q) * other.q;
p = static_cast<long long>(num);
q = static_cast<long long>(den);
normalize();
return *this;
}
fraction &operator*=(const fraction &other) {
i128 num = i128(p) * other.p;
i128 den = i128(q) * other.q;
p = static_cast<long long>(num);
q = static_cast<long long>(den);
normalize();
return *this;
}
fraction &operator/=(const fraction &other) {
if (other.p == 0)
throw std::invalid_argument("Division by zero fraction");
i128 num = i128(p) * other.q;
i128 den = i128(q) * other.p;
if (den < 0) num = -num, den = -den;
p = static_cast<long long>(num);
q = static_cast<long long>(den);
normalize();
return *this;
}
friend std::ostream &operator<<(std::ostream &os, const fraction &f) {
return os << f.p << '/' << f.q;
}
friend std::istream &operator>>(std::istream &is, fraction &f) {
char slash;
long long P, Q;
if (is >> P >> slash >> Q && slash == '/')
f = fraction(P, Q);
else
is.setstate(std::ios::failbit);
return is;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(12);
int n;
cin >> n;
int nw = 1;
rep(i, 1, 10) {
nw *= i;
if (nw == n) {
cout << "1" << endl;
return 0;
}
}
cout << "0" << endl;
}
SnowBeenDiding