結果

問題 No.3651 K-th Sum of Divisors
コンテスト
ユーザー fjbmo
提出日時 2026-08-28 23:29:44
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 492µs
コード長 1,958 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,659 ms
コンパイル使用メモリ 213,496 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-28 23:29:50
合計ジャッジ時間 5,418 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
 
#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


ll smallMod = 100003;
// ll smallMod = 13;

ll f(ll x){
    ll a = 1;
    ll ans = 0;
    while(a * a <= x){
        if(x % a == 0){
            if(a != x / a){
                ans += a + (x / a);
            }else{
                ans += a;
            }
            ans %= smallMod;
        }
        a++;
    }

    return ans;
}

int main(){
    ll N, K;
    cin >> N >> K;//cout << "f: " << f(7) << endl;

    ll visited[smallMod + 1];
    rep(i, 0, smallMod + 1){
        visited[i] = -1;
    }
    ll p = N;
    if(p <= smallMod){
        visited[p] = 1;
    }
    vector<ll> path;
    path.push_back(p);
    ll nextP = f(p);
    ll step = 1;
    while(visited[nextP] == -1){
        // rep(i, 0, path.size()){cout << path[i] << ", ";}cout << endl;
        // rep(i, 0, smallMod + 1){cout << visited[i] << ", ";}cout << endl;
        if(step == K){
            cout << p << endl;
            return 0;
        }

        p = nextP;
        visited[p] = step;
        path.push_back(p);
        step++;
        nextP = f(p);
    }

    // rep(i, 0, path.size()){cout << path[i] << ", ";}cout << endl;
    // rep(i, 0, smallMod + 1){cout << visited[i] << ", ";}cout << endl;
    ll loopSize = step - visited[nextP];//cout << "loopSize: " << loopSize << endl;
    K = (K - visited[nextP] - 1) % loopSize + visited[nextP] + 1;
    cout << path[K - 1] << endl;

    return 0;
}
0