Given a natural number k (1≤k≤18), we need to find the smallest square number with k digits, where each digit is also a square number. Input: The number of test cases t (0<t<10^3). For each test case, input a natural number k. Output: Each line corresponds to a test case and prints the found number. If no number is found, print -1. Example: Input: 2 1 3 Output: 1 100
#include<iostream> #include<cmath> using namespace std; int scp(int n){ int can = sqrt(n); if (can * can == n) return 1; else return 0; } long long find(int k){ if (k > 18){ return -1; } long long socantim = 0; for (int i = 0; i < k; i++){ int khoitao = 1; while (!scp(khoitao)){ khoitao++; } socantim = socantim * 10 + khoitao; } if (socantim == 0){ return -1; } return socantim; } int main(){ int t; cin >> t; while (t--){ int a; cin >> a; cout << find(a) << endl; } return 0; }
k
64-bit
18
Input: 2 1 3 Output: 1 100
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)