답안 #199472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199472 2020-02-01T13:44:07 Z SamAnd Trol (COCI19_trol) C++17
50 / 50
5 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 102;

int dp[N];

int sum(int x)
{
    int ans = 0;
    while (x)
    {
        ans += (x % 10);
        x /= 10;
    }
    return ans;
}

long long p(long long x)
{
    if (x == 0)
        return 0;
    long long ans = 0;
    ans += (x / 9) * (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
    for (int i = 1; i <= (x % 9); ++i)
        ans += i;
    return ans;
}

int main()
{
    /*for (int i = 1; i < N; ++i)
    {
        if (i <= 9)
            dp[i] = i;
        else
            dp[i] = dp[sum(i)];
        printf("%d %d\n", i, dp[i]);
    }*/
    int tt;
    scanf("%d", &tt);
    while (tt--)
    {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", p(r) - p(l - 1));
    }
    return 0;
}

Compilation message

trol.cpp: In function 'int main()':
trol.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &tt);
     ~~~~~^~~~~~~~~~~
trol.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct