#include <bits/stdc++.h>
#define ld long double
using namespace std;
ld r, l;
ld change(ld k)
{
long double sum = k;
while (sum >= 10)
{
long double tempSum = 0.0;
string sumStr = to_string(sum);
for (char digit : sumStr)
{
if (isdigit(digit))
{
tempSum += (digit - '0');
}
}
sum = tempSum;
}
return sum;
}
void solve()
{
cin >> r >> l;
ld ans = 0;
for (ld i = r; i <= l; i++)
{
ans += change(i);
}
cout << fixed << setprecision(0);
cout << ans << '\n';
}
int main()
{
int t = 1;
cin >> t;
while (t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
348 KB |
Output is correct |
3 |
Correct |
55 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
1061 ms |
348 KB |
Time limit exceeded |
5 |
Execution timed out |
1077 ms |
348 KB |
Time limit exceeded |