Untitled
unknown
plain_text
a year ago
999 B
1
Indexable
Never
#include <iostream> using namespace std; int X; int arr[200]; int so; int check() { int so = 0; int i = 0; while (arr[i] != 0) { so = so * 10 + arr[i]; i++; } if (so >= X && so % X == 0) { return so; } return 0; } void lucky_number(int k) { if (check() != 0) { int t = check(); if (so > t) { so = t; } return; } if (k > 9) { return; } for (int i = 0; i <= 1; i++) { if (i == 0) { // chon so 8 arr[k] = 8; lucky_number(k + 1); arr[k] = 0; } else { // chon so 6 arr[k] = 6; lucky_number(k + 1); arr[k] = 0; } } } int main() { int testcase; cin >> testcase; for (int tc = 1; tc <= testcase; tc++) { cin >> X; for (int i = 0; i < 200; i++) { arr[i] = 0; } so = 100000000; lucky_number(0); if (so != 10000000) { cout << "Case #" << tc <<endl<< so << endl; } else cout<< "Case #"<<tc<<endl<< -1 << endl; } }