Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
907 B
4
Indexable
Never
#include <stdio.h>
#include <stdbool.h>
void f(int x) {
	int array[100000], count = 0, flag = 1;
	while (true) {
		if (x == 1 && count == 0) {
			printf("%d", 1);
			break;
		}
		else if(x == 1) {
			break;
		}
		if (x % 2 != 0) {
			if (x % 3 != 0) {
				if (x % 5 != 0) {
					if (x % 7 != 0) {
						flag = 0;
						break;
					}
					else {
						array[count++] = 7;
						x /= 7;
					}
				}
				else {
					array[count++] = 5;
					x /= 5;
				}
			}
			else {
				array[count++] = 3;
				x /= 3;
			}
		}
		else {
			array[count++] = 2;
			x /= 2;
		}
	}
	if (flag) {
		for (int i = 0; i < count; i++) {
			printf("%d", array[i]);
		}
	}
	else {
		printf("%d", -1);
	}
}

void main() {
	int n, x;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (i == 0) {
			f(x);
		}
		else {
			printf("\n");
			f(x);
		}
	}
}