// Liczba Potyczkowa.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <string> #include <ctype.h> using namespace std; bool validateInput(string first, string second) { bool isNumber = true; for (char& c : first) { if (!isdigit(c)) { isNumber = false; break; } } for (char& c : first) { if (!isdigit(c) && isNumber) { isNumber = false; break; } } if (isNumber) { if (stoll(first) >= 1 && stoll(second) >= stoll(first) && (10000000000000000000>stoll(second))) { return(true); } else { return(false); } } else { return(false); } } int main(int argc, char *argv[]) { long long int l; long long int r; bool arfv_flag = false; if (argc == 3) { arfv_flag = validateInput(argv[1], argv[2]); if (arfv_flag) { l = stoll(argv[1]); r = stoll(argv[2]); } } else { arfv_flag = false; } if (!arfv_flag) { string first; string second; bool input_flag = false; while (!input_flag) { cout << "Input two interger, l and r, such that (1 <= l <= r <1018) "; cin >> first; cin >> second; input_flag = validateInput(first, second); if (input_flag) { l = stoll(first); r = stoll(second); } } } bool i_is_Potyczkowa; long long int number_of_Potyczkowa_numbers = 0; long long int number; for (long long int i = l; i <= r; i++) { i_is_Potyczkowa = true; number = i; while (number != 0) { if ((number % 10) != 0) { if ((i % (number % 10)) != 0) { i_is_Potyczkowa = false; break; } } else { i_is_Potyczkowa = false; break; } number /= 10; } if (i_is_Potyczkowa) { //cout << i << " "; number_of_Potyczkowa_numbers++; } } //cout << "\nThere are " << number_of_Potyczkowa_numbers << " Potyczkowa numbers in the range [ " << l << " , " << r << " ]\n"; return(number_of_Potyczkowa_numbers); }
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | // Liczba Potyczkowa.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <iostream> #include <string> #include <ctype.h> using namespace std; bool validateInput(string first, string second) { bool isNumber = true; for (char& c : first) { if (!isdigit(c)) { isNumber = false; break; } } for (char& c : first) { if (!isdigit(c) && isNumber) { isNumber = false; break; } } if (isNumber) { if (stoll(first) >= 1 && stoll(second) >= stoll(first) && (10000000000000000000>stoll(second))) { return(true); } else { return(false); } } else { return(false); } } int main(int argc, char *argv[]) { long long int l; long long int r; bool arfv_flag = false; if (argc == 3) { arfv_flag = validateInput(argv[1], argv[2]); if (arfv_flag) { l = stoll(argv[1]); r = stoll(argv[2]); } } else { arfv_flag = false; } if (!arfv_flag) { string first; string second; bool input_flag = false; while (!input_flag) { cout << "Input two interger, l and r, such that (1 <= l <= r <1018) "; cin >> first; cin >> second; input_flag = validateInput(first, second); if (input_flag) { l = stoll(first); r = stoll(second); } } } bool i_is_Potyczkowa; long long int number_of_Potyczkowa_numbers = 0; long long int number; for (long long int i = l; i <= r; i++) { i_is_Potyczkowa = true; number = i; while (number != 0) { if ((number % 10) != 0) { if ((i % (number % 10)) != 0) { i_is_Potyczkowa = false; break; } } else { i_is_Potyczkowa = false; break; } number /= 10; } if (i_is_Potyczkowa) { //cout << i << " "; number_of_Potyczkowa_numbers++; } } //cout << "\nThere are " << number_of_Potyczkowa_numbers << " Potyczkowa numbers in the range [ " << l << " , " << r << " ]\n"; return(number_of_Potyczkowa_numbers); } |