結果

問題 No.2032 Let's Write Multiples!!
ユーザー JashinchanJashinchan
提出日時 2022-08-24 11:59:03
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 32,000 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-20 02:43:17
合計ジャッジ時間 7,049 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'solver':
main.c:25:36: warning: implicit declaration of function 'pow' [-Wimplicit-function-declaration]
   25 |         ans += solver_inner(n, c * pow(10, (d - 1)), k, pow(10, d)) - solver_inner(n, (c + 1) * pow(10, d - 1), k, pow(10, d));
      |                                    ^~~
main.c:2:1: note: include '<math.h>' or provide a declaration of 'pow'
    1 | #include <stdio.h>
  +++ |+#include <math.h>
    2 | 
main.c:25:36: warning: incompatible implicit declaration of built-in function 'pow' [-Wbuiltin-declaration-mismatch]
   25 |         ans += solver_inner(n, c * pow(10, (d - 1)), k, pow(10, d)) - solver_inner(n, (c + 1) * pow(10, d - 1), k, pow(10, d));
      |                                    ^~~
main.c:25:36: note: include '<math.h>' or provide a declaration of 'pow'

ソースコード

diff #

#include <stdio.h>

unsigned long long int floor_sum(long long a, long long b, long long m, long long n)
{
    unsigned long long int ans = a / m * ((n - 1) * n / 2) + b / m * n;
    a %= m;
    b %= m;
    if (!a)
        return ans;
    unsigned long long int n2 = (a * n + b) / m;
    return ans + (n - 1) * n2 - floor_sum(n2, a, m, m - 1 - b);
}

long long solver_inner(long long n, long long x, long long k, long long d)
{
    return n - (floor_sum(k, k, d, n) - floor_sum(k, k - x, d, n));
}
long long solver(long long lim, long long k, long long c)
{
    long long n = lim / k;
    if (n <= 0)
        return 0;
    long long ans = 0;
    for (long long d = 1; d <= 9; ++d)
        ans += solver_inner(n, c * pow(10, (d - 1)), k, pow(10, d)) - solver_inner(n, (c + 1) * pow(10, d - 1), k, pow(10, d));
    return ans;
}
void solve(void)
{
    long long L, R, K, C;
    scanf("%lld%lld%lld%lld", &L, &R, &K, &C);
    printf("%lld\n", solver(R, K, C) - solver(L - 1, K, C));
}

int main(void)
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        solve();
    }
    return 0;
}
0