Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Digit cancelling fractions
- The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
- We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
- There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
- If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
- *
- * (10*a + b)/(10*b + c) = a / c
- * a * (10 * b + c) = c * (10 * a + b)
- * and
- * a =/= b =/= c
- * we have a digit cancelling fraction
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- namespace home_project
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stopwatch sw = new Stopwatch();
- sw.Start();
- float final_nom = 1;
- float final_denom = 1;
- for (float a = 1; a < 10; a++)
- {
- for (float b = a; b < 10; b++)
- {
- for (float c = 1; c < 10; c++)
- {
- float nom = a * 10 + b;
- float denom = b * 10 + c;
- if (nom < denom)
- {
- if ( (nom / denom) == (a / c))
- {
- final_nom = nom;
- final_denom = denom;
- Console.WriteLine("Conditions are fullfilled for this fraction:\n" + final_nom + " / " + final_denom + "\nProof: " + final_nom + " / " + final_denom + " = " + nom / denom + " & " + a + " / " + c + " = " + nom / denom);
- }
- }
- }
- }
- }
- sw.Stop();
- Console.WriteLine("Problem completed in {0}ms", sw.ElapsedMilliseconds);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement