Blue Bridge Cup enumeration odd fraction
Title: The odd fraction
When he was in elementary school, Xiaoming often invented his own new algorithm. Once, the teacher's topic is:
1/4 Times 8/5.
Xiao Ming actually put the molecules together, the denominator stitching together, the answer is: 18/45 (see figure 1.png)
The teacher was just trying to criticize him, and then he thought, the answer happened.
For the numerator and denominator are all one-digit numbers in the 1~9, what other formulas can be computed like this?
Please write down the number of all the different formulas (including examples in the question).
Obviously, after the numerator's denominator, for example: 4/1 times 5/8 is satisfying, this is a different formula.
But for the same numerator denominator, 2/2 times 3/3 has too many types, not counting!
Note: The answer is an integer (consider symmetry, which is definitely an even number). Please submit via browser. Don't write extra content.
Very simple, if the brute force enumeration is not a problem, with a DFS deep search code looks simple, in addition, familiar with GCD, the two scores of the greatest common divisor, divide the convention number, then to determine whether the two scores are the same.
Answer: 14
The code is as follows
1#include <iostream>2#include <cstdio>3 #defineMAXN 54 using namespacestd;5 intnum[maxn],s1,s2,r1,r2;6 intCount=0;7 intgcdintAintb)8 {9 ints;Ten while(b) One { As=a%b; -A=b; -b=s; the } - returnA; - } - voidDfsintm) + { - inti,j,a,b,t,ss1,ss2,rr1,rr2; + if(m==5) A { at if(num[1]!=num[2]&&num[3]!=num[4]) - { -s1=num[1]*Ten+num[3]; -s2=num[2]*Ten+num[4]; -r1=num[1]*num[3]; -r2=num[2]*num[4]; in if(r1<R2) - { toA=R2; +b=R1; -t=gcd (A, b); the } * Else $ {Panax NotoginsengA=R1; -b=R2; thet=gcd (A, b); + } Arr1=r1/T; therr2=r2/T; + if(s1<S2) - { $A=S2; $b=S1; -t=gcd (A, b); - } the Else - {WuyiA=S1; theb=S2; -t=gcd (A, b); Wu } -ss1=s1/T; Aboutss2=s2/T; $ if(rr1==ss1&&rr2==SS2) - { -cout<<num[1]<<"/"<<num[2]<<" * "<<num[3]<<"/"<<num[4]<<" = "<<num[1]<<num[3]<<"/"<<num[2]<<num[4]<<Endl; -count++; A } + } the } - Else $ { the for(i=1; i<=9; i++) the { thenum[m]=i; theDFS (m+1); - } in } the } the intMain () About { theDfs1); thecout<<count<<Endl; the return 0; +}
Blue Bridge Cup 2014 undergraduate C + + Group B Strange Fractional Violence enumeration