結果

問題 No.1252 数字根D
ユーザー fastmathfastmath
提出日時 2020-10-09 23:21:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 197,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 19:44:50
合計ジャッジ時間 2,629 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif
    
    auto mod = [&] (int n, int m) {
        if (n % m == 0)
            return m;
        else
            return n % m;
    };  

    int t;
    cin >> t;

    auto f = [&] (int n, int d) {
        int ans = 0;
        while (n) {
            ans += n % d;
            n /= d;
        }
        return ans;
    };

    auto sum = [&] (int n) {
        return n * (n + 1) / 2;
    };  

    auto solve = [&] (int d, int n) {

        if (n <= 0)
            return 0ll;

        int c = n/(d-1);
        int rem = n % (d - 1);
        return c * sum(d - 1) + sum(rem);
        
        /*
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            ans += mod(i, d - 1);            
        }   
        return ans;
        */
    };  


    while (t--) {
        int d, l, r;
        cin >> d >> l >> r;
        cout << solve(d, r) - solve(d, l - 1) << endl;
    }
    
}
    
0