結果

問題 No.2177 Recurring ab
ユーザー milanis48663220
提出日時 2023-01-06 21:58:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,919 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 113,576 KB
最終ジャッジ日時 2025-02-09 23:55:19
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n; cin >> n;
    auto sub_solve = [&](int a, int b){
        auto ok = [&](ll p){
            return n*(p*a+b) > p*p-1;
        };
        ll l = max(a, b)+1, r = 1e9;
        if(!ok(l)) return 0ll;
        if(ok(r)){
            return r-max(a, b);
        }
        while(r-l > 1){
            ll p = (l+r)/2;
            if(ok(p)) l = p;
            else r = p;
        }
        ll ans = l-max({a, b, 1});
        return ans;
    };
    ll ans = 0;
    for(int a = 0; a <= 9; a++){
        for(int b = 0; b <= 9; b++){
            if(a == b) continue;
            ans += sub_solve(a, b);
        }
    }
    cout << ans << endl;
}
0