結果

問題 No.415 ぴょん
ユーザー nanophoto12nanophoto12
提出日時 2016-09-22 21:16:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,709 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 89,372 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-28 18:29:21
合計ジャッジ時間 3,192 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

const ll mod = (ll)(1e9+7);

struct SimpleHash {
    size_t operator()(const std::pair<ll, ll>& p) const {
        return p.first * mod + p.second;
    }
};

int main()
{
    ll n, d;
    cin >> n >> d;
    
    ll front = 0;
    ll c = 0;
    if(d > n)
    {
        d = d % n;
    }
    if(d == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    if(n == d)
    {
        cout << 0 << endl;
        return 0;
    }
    while(true)
    {
        ll rest = (n-front) % d;
        c += (n-front) / d;
        if(rest == 0)
        {
            break;
        }
        front = - rest;
    }
    cout << c-1 << endl;
    return 0;
}
0