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;
}
相关推荐
九.九16 小时前
CANN HCOMM 底层机制深度解析:集合通信算法实现、RoCE 网络协议栈优化与多级同步原语
网络·网络协议·算法
C++ 老炮儿的技术栈16 小时前
Qt Creator中不写代如何设置 QLabel的颜色
c语言·开发语言·c++·qt·算法
子春一16 小时前
Flutter for OpenHarmony:构建一个 Flutter 数字消消乐游戏,深入解析网格状态管理、合并算法与重力系统
算法·flutter·游戏
草履虫建模1 天前
力扣算法 1768. 交替合并字符串
java·开发语言·算法·leetcode·职场和发展·idea·基础
naruto_lnq1 天前
分布式系统安全通信
开发语言·c++·算法
Jasmine_llq1 天前
《P3157 [CQOI2011] 动态逆序对》
算法·cdq 分治·动态问题静态化+双向偏序统计·树状数组(高效统计元素大小关系·排序算法(预处理偏序和时间戳)·前缀和(合并单个贡献为总逆序对·动态问题静态化
爱吃rabbit的mq1 天前
第09章:随机森林:集成学习的威力
算法·随机森林·集成学习
(❁´◡`❁)Jimmy(❁´◡`❁)1 天前
Exgcd 学习笔记
笔记·学习·算法
YYuCChi1 天前
代码随想录算法训练营第三十七天 | 52.携带研究材料(卡码网)、518.零钱兑换||、377.组合总和IV、57.爬楼梯(卡码网)
算法·动态规划
不能隔夜的咖喱1 天前
牛客网刷题(2)
java·开发语言·算法