B. The Secret Number

time limit per test

2 seconds

memory limit per test

256 megabytes

Vadim has thought of a number x. To ensure that no one can guess it, he appended a positive number of zeros to the right of it, thus obtaining a new number y. However, as a precaution, Vadim decided to spread the number n=x+y. Find all suitable x that Vadim could have thought of for the given n.

Input

Each test consists of several test cases. The first line contains a single integer t (1≤t≤104) --- the number of test cases. The following lines describe the test cases.

In a single line of each test case, there is an integer n --- the number spread by Vadim (11≤n≤1018).

Output

For each number n, output 0 if there are no suitable x. Otherwise, output the number of suitable x, followed by all suitable x in ascending order.

Example

Input

Copy

复制代码

5

1111

12

55

999999999999999999

1000000000000000000

Output

Copy

复制代码
2
11 101
0
1
5
3
999999999 999000999000999 90909090909090909
0

Note

In the first sample, to 11 one can append two zeros to the right, then 11+1100=1111, and to 101 one can append one zero to the right, then 101+1010=1111.

In the second sample, it is impossible to obtain 12 through the described actions.

解题说明:此题是一道数学题,给出一个N,是否能找出一个X,使得X+Y=N,其中Y = X ∗ 10 ^K,求解X+X ∗ 10 ^K=N。 因为N范围小于10^18次方,因此K最多为18.直接求解即可。

cpp 复制代码
#include <stdio.h>
int main()
{
	long long t; 
	scanf("%lld", &t);
	while (t--) 
	{
		long long n; 
		scanf("%lld", &n);
		long long test = 1, testt[64];
		int cnt = 0;
		for (int k = 1; k <= 18; k++)
		{
			test *= 10;
			long long d = test + 1;
			if (n % d == 0)
			{
				testt[cnt++] = n / d;
			}
		}
		if (cnt == 0) 
		{
			printf("0\n");
			continue;
		}
		printf("%d\n", cnt);
		for (int i = cnt - 1; i >= 0; i--)
		{
			printf("%lld", testt[i]);
			if (i)
			{
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}
相关推荐
x_yeyue1 小时前
三角形数
笔记·算法·数论·组合数学
念何架构之路2 小时前
Go语言加密算法
数据结构·算法·哈希算法
AI科技星2 小时前
《数学公理体系·第三部·数术几何》(2026 年版)
c语言·开发语言·线性代数·算法·矩阵·量子计算·agi
失去的青春---夕阳下的奔跑2 小时前
560. 和为 K 的子数组
数据结构·算法·leetcode
黎阳之光3 小时前
黎阳之光:以视频孪生重构智慧医院信息化,打造高标项目核心竞争力
大数据·人工智能·物联网·算法·数字孪生
丷丩3 小时前
三级缓存下MVT地图瓦片服务性能优化策略
算法·缓存·性能优化·gis·geoai-up
m0_629494733 小时前
LeetCode 热题 100-----25.回文链表
数据结构·算法·leetcode·链表
ʚ希希ɞ ྀ4 小时前
单词拆分----dp
算法
智者知已应修善业5 小时前
【51单片机LED闪烁10次数码管显示0-9】2023-12-14
c++·经验分享·笔记·算法·51单片机
智者知已应修善业5 小时前
【51单片机2按键控制1个敞亮LED灯闪烁和熄灭】2023-11-3
c++·经验分享·笔记·算法·51单片机