結果

問題 No.136 Yet Another GCD Problem
ユーザー memmemmi
提出日時 2018-09-19 14:05:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 888 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 110,508 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-18 08:14:40
合計ジャッジ時間 2,129 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

int gcd(int a, int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}


int main() {
    int n,k;
    cin>>n>>k;

    int res = -1;
    for (int i = 1; i <=(n/2)+1; i++) {
        if(n-i<n/2)continue;
        res=max(res,gcd(n-i,i));
    }

    cout<<res<<endl;

    return 0;
}
0