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;
}
相关推荐
前端小L1 小时前
贪心算法专题(十):维度权衡的艺术——「根据身高重建队列」
javascript·算法·贪心算法
方得一笔1 小时前
自定义常用的字符串函数(strlen,strcpy,strcmp,strcat)
算法
Xの哲學2 小时前
Linux SMP 实现机制深度剖析
linux·服务器·网络·算法·边缘计算
wuk9982 小时前
使用PCA算法进行故障诊断的MATLAB仿真
算法·matlab
额呃呃2 小时前
二分查找细节理解
数据结构·算法
无尽的罚坐人生2 小时前
hot 100 283. 移动零
数据结构·算法·双指针
永远都不秃头的程序员(互关)2 小时前
C++动态数组实战:从手写到vector优化
c++·算法
水力魔方3 小时前
武理排水管网模拟分析系统应用专题5:模型克隆与并行计算
数据库·c++·算法·swmm
谈笑也风生4 小时前
经典算法题型之排序算法(三)
java·算法·排序算法
大佬,救命!!!5 小时前
对算子shape相关的属性值自动化处理
python·算法·自动化·学习笔记·算子·用例脚本·算子形状