結果

問題 No.415 ぴょん
ユーザー kpinkcatkpinkcat
提出日時 2023-12-12 10:56:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 964 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 109,260 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-12 10:56:23
合計ジャッジ時間 2,715 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<bitset>
#include<math.h>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;
using ll = long long;

int main()
{
    ll n, d, mod = -1, frac = 0, a;
    cin >> n >> d;
    mod = n % d;
    a = pow(n, 0.5);
    vector<ll> p(a+1, 1);
    p[0] = 0;
    p[1] = 0;
    for (int i = 2; i <= a; i++){
        if (p[i]) for (int j = i*i; j <= a; j += i) p[j] = 0;
    }
    if (!mod) cout << (n-1)/d << endl;
    else if (n == d) cout << 0 << endl;
    else if (!(d%mod)) {
        frac = d/mod;
        cout << n*frac/d - 1 << endl;
        return 0;
    } else {
        for (int i = 2; i <= min({d, mod, a}); i++){
            if (p[i]){
                if (!(d%i) && !(mod%i)) {
                frac = i;
                cout << n*frac/d -1 << endl;
                return 0;
                }
            }
        }
        cout << n -1 << endl;
    }
}
0