2014 The fifth session of the Blue Bridge Cup test-C + + program Design Group B-Strange fraction

Source: Internet
Author: User

Title Description:


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.

Program code:

  

#include <stdio.h>
#include <math.h>
int count;//for statistic count

Error
#define EPS 10e-10


int main () {
int i,j,m,n;
for (i = 1;i<=9;++i) {
for (j = 1;j<=9;++j) {
for (m=1;m<=9;++m) {
for (n=1;n<=9;n++) {
if ((i==j) | | | (m==n)) Continue
if (Fabs (i*10+m) *1.0/(j*10+n)-(i*m*1.0)/(j*n)) <eps) {//Plus and multiply do absolute comparisons

count++;
}
}
}
}
}
printf ("%d", count);


return 0;
}

Final results: 14

2014 The fifth session of the Blue Bridge Cup test-C + + program Design Group B-Strange fraction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.