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;
}
相关推荐
地平线开发者1 小时前
ReID/OSNet 算法模型量化转换实践
算法·自动驾驶
地平线开发者2 小时前
开发者说|EmbodiedGen:为具身智能打造可交互3D世界生成引擎
算法·自动驾驶
星星火柴9363 小时前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
艾莉丝努力练剑3 小时前
【洛谷刷题】用C语言和C++做一些入门题,练习洛谷IDE模式:分支机构(一)
c语言·开发语言·数据结构·c++·学习·算法
C++、Java和Python的菜鸟5 小时前
第六章 统计初步
算法·机器学习·概率论
Cx330❀5 小时前
【数据结构初阶】--排序(五):计数排序,排序算法复杂度对比和稳定性分析
c语言·数据结构·经验分享·笔记·算法·排序算法
散1125 小时前
01数据结构-Prim算法
数据结构·算法·图论
起个昵称吧5 小时前
线程相关编程、线程间通信、互斥锁
linux·算法
myzzb6 小时前
基于uiautomation的自动化流程RPA开源开发演示
运维·python·学习·算法·自动化·rpa
旺小仔.7 小时前
双指针和codetop复习
数据结构·c++·算法