結果

問題 No.1252 数字根D
ユーザー sapphire__15sapphire__15
提出日時 2020-10-09 21:48:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,829 bytes
コンパイル時間 943 ms
コンパイル使用メモリ 104,660 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 10:33:05
合計ジャッジ時間 1,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# ifndef ONLINE_JUDGE
template<typename T>
void vdeb(std::vector<T> &bb) {
    for (int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &bb) {
    for (int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

ll solve() {
    ll d, a, b; cin >> d >> a >> b;
    ll ans = 0;
    ans += (d-1)*d/2*(b/(d-1));
    b %= d-1;
    ans += (b+1)*b/2;
    if(a) --a;
    ans -= (d-1)*d/2*(a/(d-1));
    a %= d-1;
    ans -= (a+1)*a/2;
    return ans;
}

int main() {
    int t; cin >> t;
    vector<ll> ans(t);
    rip(i,t,0) ans[i] = solve();
    rip(i,t,0) printf("%lld\n", ans[i]);
}
0