100 can be expressed as a fractional form: 3+69258/714 or 82+3546/197. Similar to the band score, 100 total 11 kinds of notation. With fractions, the digital 1~9 appear only once (not including 0).
Please write a C + + program, enter a positive integer n (n<1000000), Output n with a digital 1~9 do not omit to make up the total number of fractional representation. For example, enter 100, output 11, and 105, then output 6. Note: It is not required to output each representation, only output all the number of numbers with fractional notation!
#include <iostream>
#include <algorithm>
using namespace Std;
int f (int start, int end,int *arr) {
if (Start > End)
return 1;
int n = 0;
for (int i = start; I <= end; i++) {
n = n * + arr[i];
}
return n;
}
int size (int n) {
int count=0;
while (n) {
count++;
n/= 10;
}
return count;
}
int main () {
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int n, a, b, c,count=0;
CIN >> N;
do{
for (int i = 0; I <= size (n); i++) {
for (int j = i; J < 8; J + +) {
A = f (0, I, arr);
b = f (i + 1, J, arr);
c = f (j + 1, 8, arr);
if (n = = a + b/c && b% c = = 0) {
count++;
cout << a << "+" << B << "/" << c << Endl;
}
}
}
} while (Next_permutation (arr, arr + 9));
cout << Count << Endl;
}
Blue Bridge Cup/C + + band fraction