-
Notifications
You must be signed in to change notification settings - Fork 0
/
471MagicNumbers.cpp
64 lines (44 loc) · 1.22 KB
/
471MagicNumbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Vasudev Vijayaraman
// 471 - Magic Numbers
// UVA login name - vasapp
// Data Structure required - Vector
// Tricks - Using the isUnique function to extract one digit at a time
#include "stdafx.h"
#include <iostream>
using namespace std;
bool isUnique(long long input) {
int setNumber[10] = { 0 };
while (input) {
setNumber[input % 10]++; // extracting one digit at a time
if (setNumber[input % 10] > 1) { // if the remainder is more than 1
return false;
}
input /= 10; // extracting digits
}
return true;
}
int main() {
int testCases; // read in testcases
long long Largest = 9876543210LL;
long long input = 9876543210LL; // input is long long since it is a big number
cin >> testCases;
for (int i = 0; i < testCases; i++) {
cin >> input; // input reading in
//cout << input;
long long first_num = input;
long long second_num = 1;
while (true) {
if (isUnique(first_num) && isUnique(second_num))
cout << first_num << " / " << second_num << " = " << input << endl;
first_num = first_num + input;
second_num++;
if (first_num > Largest){
break;
}
}
if (testCases) {
cout << endl;
}
}
return 0;
}