C. Vlad and a Sum of Sum of Digits

time limit per test

0.5 seconds

memory limit per test

256 megabytes

Please note that the time limit for this problem is only 0.5 seconds per test.

Vladislav wrote the integers from 11 to nn, inclusive, on the board. Then he replaced each integer with the sum of its digits.

What is the sum of the numbers on the board now?

For example, if n=12n=12 then initially the numbers on the board are:

1,2,3,4,5,6,7,8,9,10,11,12.1,2,3,4,5,6,7,8,9,10,11,12.

Then after the replacement, the numbers become:

1,2,3,4,5,6,7,8,9,1,2,3.1,2,3,4,5,6,7,8,9,1,2,3.

The sum of these numbers is 1+2+3+4+5+6+7+8+9+1+2+3=511+2+3+4+5+6+7+8+9+1+2+3=51. Thus, for n=12n=12 the answer is 5151.

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) --- the number of test cases.

The only line of each test case contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) --- the largest number Vladislav writes.

Output

For each test case, output a single integer --- the sum of the numbers at the end of the process.

Example

Input

Copy

复制代码

7

12

1

2

3

1434

2024

200000

Output

Copy

复制代码
51
1
3
6
18465
28170
4600002

解题说明:此题其实是求数列之和,两位数以上就需要把数字全部加起来求和,为了保证时间,可以先把输入范围1-200000内的结果全部计算出来,后面根据输入的n值直接输出答案即可。

cpp 复制代码
#include<stdio.h>

int digitsum(int n)
{
	if (n == 0)
	{
		return 0;
	}
	int m = n % 10;
	return m + digitsum(n / 10);
}



int main() 
{
	int t;
	scanf("%d", &t);
	int ar[200001];
	ar[0] = 1;
	for (int i = 0; i < 200001; i++)
	{
		ar[i] = ar[i - 1] + digitsum(i + 1);
	}
	while (t--) 
	{
		int n;
		scanf("%d", &n);
		printf("%d\n", ar[n - 1]);
	}
	return 0;
}
相关推荐
Godspeed Zhao16 分钟前
从零开始学AI16——SVM
算法·机器学习·支持向量机
江屿风26 分钟前
C++OJ题经验总结(竞赛)1
开发语言·c++·笔记·算法
nebula-AI28 分钟前
人工智能导论:模型与算法(核心技术)
人工智能·深度学习·神经网络·算法·机器学习·集成学习·sklearn
运筹vivo@1 小时前
LeetCode 2405. 子字符串的最优划分
c++·算法·leetcode·职场和发展·哈希表
数智工坊1 小时前
视觉-语言-动作模型解剖学:从模块、里程碑到核心挑战
论文阅读·人工智能·深度学习·算法·transformer
有点。1 小时前
C++(枚举法一练习题)
开发语言·c++·算法
黎阳之光1 小时前
视听融合新范式!黎阳之光打破视觉边界,声影协同赋能全域智慧管控
大数据·人工智能·物联网·算法·数字孪生
玖釉-2 小时前
栈——栈的定义及基本操作
c++·windows·算法·图形渲染
ゆづき2 小时前
Java 初学者入门指南:常见问题 + 核心知识点 + 进阶 20 道练习题
java·开发语言·学习·算法·水题
Evand J3 小时前
【课题推荐】强跟踪UKF算法,三维非线性状态量和观测量,附MATLAB代码测试结果
开发语言·算法·matlab