Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- long int fact(int N){
- if (N < 0)
- return 0;
- if (N == 0)
- return 1;
- else
- return N * fact(N - 1);
- }
- void check(int n, int& N) {
- int B[10] = { 0 };
- while (n > 0) {
- B[n % 10]++;
- n /= 10;
- }
- for (int i = 0; i < 10; i++) {
- if (B[i] > 1) {
- N--;
- }
- }
- }
- bool Num(int N){
- int p, sum;
- p = 1;
- sum = 0;
- while (N > 0)
- {
- sum += N % 10;
- p *= N % 10;
- N /= 10;
- }
- if (p == sum)
- return true;
- return false;
- }
- int main()
- {
- ifstream fin("INPUT.txt");
- int N = 0, k = 0;
- long long num = 0, b = 0, i = 0;
- fin >> N;
- fin.close();
- ofstream fout("OUTPUT.txt");
- if (N == 1)
- fout << 10 << " " << 0;
- else
- {
- i = pow(10, N - 1);
- b = pow(10, N);
- while ((k == 0) && (i < b)) {
- if (Num(i)){
- check(i, N);
- k = fact(N);
- num = i;
- }
- ++i;
- }
- fout << k << " " << num;
- }
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement