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;
}
相关推荐
小程故事多_803 小时前
从A2C、TRPO、PPO到GRPO,强化学习策略梯度算法完整演进与大模型落地实战解析
人工智能·算法
2601_956121975 小时前
二分算法(知识点+题目)
c++·算法
AndrewHZ7 小时前
【LLM技术全景】阶段总结:技术原理篇核心知识回顾
人工智能·深度学习·算法·语言模型·大模型·llm·芯片开发
小星星闪亮登场8 小时前
2026萌新联赛第三场-- (郑州轻工业大学)
数据结构·c++·经验分享·算法·贪心算法·排序算法·深度优先
冻柠檬飞冰走茶9 小时前
PTA基础编程题目集 7-8超速判断(C++语言实现)
开发语言·数据结构·c++·算法
玖玥拾9 小时前
LeetCode 88 合并两个有序数组
算法·leetcode
数据皮皮侠AI9 小时前
上市公司数字供应链金融指数(2010-2024)
大数据·人工智能·算法
小程故事多_8010 小时前
用GRPO算法重塑多智能体系统,从原理落地到复杂任务规划实战
人工智能·算法
Hi李耶10 小时前
【LeetCode】541.反转字符串 II
算法·leetcode·职场和发展
shylyly_10 小时前
104.二叉树的最大深度
数据结构·算法·104.二叉树的最大深度