結果

問題 No.1794 Continued Fraction
ユーザー KiogollKiogoll
提出日時 2022-02-13 11:37:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 5,190 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 176,012 KB
実行使用メモリ 26,544 KB
最終ジャッジ日時 2023-09-11 15:22:22
合計ジャッジ時間 4,730 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
26,232 KB
testcase_01 AC 10 ms
26,464 KB
testcase_02 AC 10 ms
26,300 KB
testcase_03 AC 10 ms
26,232 KB
testcase_04 AC 11 ms
26,480 KB
testcase_05 AC 10 ms
26,236 KB
testcase_06 AC 10 ms
26,480 KB
testcase_07 AC 10 ms
26,264 KB
testcase_08 AC 11 ms
26,444 KB
testcase_09 AC 10 ms
26,268 KB
testcase_10 AC 11 ms
26,528 KB
testcase_11 AC 11 ms
26,528 KB
testcase_12 AC 10 ms
26,200 KB
testcase_13 AC 10 ms
26,240 KB
testcase_14 AC 10 ms
26,368 KB
testcase_15 AC 10 ms
26,192 KB
testcase_16 AC 10 ms
26,404 KB
testcase_17 AC 10 ms
26,368 KB
testcase_18 AC 10 ms
26,240 KB
testcase_19 AC 10 ms
26,456 KB
testcase_20 AC 11 ms
26,476 KB
testcase_21 AC 10 ms
26,412 KB
testcase_22 AC 11 ms
26,396 KB
testcase_23 AC 10 ms
26,232 KB
testcase_24 AC 11 ms
26,252 KB
testcase_25 AC 10 ms
26,476 KB
testcase_26 AC 9 ms
26,468 KB
testcase_27 AC 10 ms
26,544 KB
testcase_28 AC 10 ms
26,324 KB
testcase_29 AC 11 ms
26,352 KB
testcase_30 AC 10 ms
26,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘std::string smax(std::string, std::string)’ 内:
main.cpp:121:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
  121 | }
      | ^
main.cpp: 関数 ‘std::string smin(std::string, std::string)’ 内:
main.cpp:139:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
  139 | }
      | ^

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll _mod = 998244353;
const ll _MOD = 1000000007;
const ll INF = 1ll << 60;
const ll inf = -(1ll << 60);
const double PI = 3.141592653589793;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
struct union_find {
  vector<ll> p, s;
  union_find(ll n) : p(n, -1), s(n, 1) {}
  ll root(ll x) {
    if (p[x] == -1) return x;
    else return p[x] = root(p[x]);
  }
  bool same(ll x, ll y) { return root(x) == root(y); }
  ll unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (s[x] < s[y]) swap(x, y);
    p[y] = x;
    s[x] += s[y];
    return true;
  }
  ll size(ll x) { return s[root(x)]; }
};
struct BIT {
public:
  ll n;
  vector<ll> a;
  BIT(ll n) :n(n), a(n + 1, 0) {}
  void add(ll i, ll x) {
    i++;
    if (i == 0) return;
    for (ll k = i; k <= n; k += (k & -k)) {
      a[k] += x;
    }
  }
  ll sum(ll i, ll j) {
    return sum_sub(j) - sum_sub(i - 1);
  }
  ll sum_sub(ll i) {
    i++;
    ll s = 0;
    if (i == 0) return s;
    for (ll k = i; k > 0; k -= (k & -k)) {
      s += a[k];
    }
    return s;
  }
  ll lower_bound(ll x) {
    if (x <= 0) {
      return 0;
    }
    else {
      ll i = 0; ll r = 1;
      while (r < n) r = r << 1;
      for (int len = r; len > 0; len = len >> 1) {
        if (i + len < n && a[i + len] < x) {
          x -= a[i + len];
          i += len;
        }
      }
      return i;
    }
  }
};
struct segment_tree {
private:
  ll n;
  vector<ll> node;
public:
  segment_tree(vector<ll> v) {
    ll sz = v.size();
    n = 1; while (n < sz) n *= 2;
    node.resize(2 * n - 1, INF);

    for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (ll i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(ll x, ll val) {
    x += (n - 1);

    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  ll getmin(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
    // [a, b)
    if (r < 0) r = n;
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return node[k];

    ll vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
string smax(string x, string y) {
  if (x == y) return x;
  if (x == "inf") return y;
  if (y == "inf") return x;
  if (x == "INF" || y == "INF") return "INF";
  if (x[0] == '-' && y[0] == '-') {
    if (x.size() > y.size()) return y;
    if (x.size() < y.size()) return x;
    if (x.size() == y.size() && x > y) return y;
    if (x.size() == y.size() && x < y) return x;
  }
  if (x[0] == '-') return y;
  if (y[0] == '-') return x;
  if (x.size() > y.size()) return x;
  if (x.size() < y.size()) return y;
  if (x.size() == y.size() && x > y) return x;
  if (x.size() == y.size() && x < y) return y;
}
string smin(string x, string y) {
  if (x == y) return x;
  if (x == "INF") return y;
  if (y == "INF") return x;
  if (x == "inf" || y == "inf") return "inf";
  if (x[0] == '-' && y[0] == '-') {
    if (x.size() > y.size()) return x;
    if (x.size() < y.size()) return y;
    if (x.size() == y.size() && x > y) return x;
    if (x.size() == y.size() && x < y) return y;
  }
  if (x[0] == '-') return x;
  if (y[0] == '-') return y;
  if (x.size() > y.size()) return y;
  if (x.size() < y.size()) return x;
  if (x.size() == y.size() && x > y) return y;
  if (x.size() == y.size() && x < y) return x;
}
vector<pair<ll, ll>> prime_factorization(ll x) {
  vector<pair<ll, ll>> ans(0);
  for (ll p = 2; p * p <= x; ++p) {
    if (!(x % p)) {
      ll e = 0;
      while (!(x % p)) {
        x %= p;
        ++e;
      }
      ans.push_back({ p,e });
    }
  }
  if (x != 1) ans.push_back({ x,1 });
  return ans;
}
ll phi(ll x) {
  const auto& pf = prime_factorization(x);
  ll ans = x;
  for (pair<ll, ll> p : pf) {
    ans *= (p.first - 1);
    ans *= p.first;
  }
  return ans;
}
ll modinv(ll x, ll MOD) {
  ll y = MOD, u = 1, v = 0;
  while (y) {
    ll t = x / y;
    x -= t * y; swap(x, y);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}
ll modpow(ll a, ll n, ll MOD) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1) ans = ans * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return ans;
}
ll GCD(ll x, ll y) { return (y == 0 ? x : GCD(y, x % y)); }
vector<ll> _f(1000001), _finv(1000001), _inv(1000001);
void Cinit(ll MOD) {
  _f[0] = 1;  _f[1] = 1;
  _finv[0] = 1; _finv[1] = 1;
  _inv[1] = 1;
  for (ll i = 2; i < 1000001; ++i) {
    _f[i] = _f[i - 1] * i % MOD;
    _inv[i] = MOD - _inv[MOD % i] * (MOD / i) % MOD;
    _finv[i] = _finv[i - 1] * _inv[i] % MOD;
  }
}
ll modnCr(ll n, ll r, ll MOD) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return _f[n] * (_finv[r] * _finv[n - r] % MOD) % MOD;
}
ll modnHr(ll n, ll r, ll MOD) {
  return modnCr(n + r - 1, r, MOD);
}
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> ans(0);
  while (M) {
    ans.push_back(N / M);
    N = N % M;
    swap(N, M);
  }
  for (ll i = 0; i < ans.size(); ++i) cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
}
0