Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Solution
- {
- public const double PI = 3.1415926535897932384626433832795028841971693993751;
- static void Main(String[] args)
- {
- string[] tokens_min = Console.ReadLine().Split(' ');
- long min = Convert.ToInt64(tokens_min[0]);
- long max = Convert.ToInt64(tokens_min[1]);
- //--- my code ---
- double n = 1;
- double d = 1;
- for (double i = min; i < max; i++)
- {
- double difference = 1;
- double minimal = 10;
- for (double j = 1; (j / d) <= PI; j++)
- {
- Console.WriteLine("{0}/{1}", j, i);
- double lowerBound = j - 1;
- double upperBound = j;
- double lowerDifference = Math.Abs(lowerBound / d - PI);
- double upperDifference = Math.Abs(lowerBound / d - PI);
- /*Console.WriteLine("For lower boundary {2}, the difference is {0}" +
- "\n For upper boundary {3}, the difference is {1}",
- lowerDifference, upperDifference, lowerBound, upperBound);
- */
- if (lowerDifference < upperDifference)
- {
- difference = lowerDifference;
- if (difference < minimal)
- {
- minimal = difference;
- d = i;
- n = lowerBound;
- Console.WriteLine("Minimal value: {0}", minimal);
- }
- }
- else
- {
- difference = upperDifference;
- if (difference < minimal)
- {
- minimal = difference;
- d = i;
- n = upperBound;
- Console.WriteLine("Minimal value: {0}", minimal);
- }
- }
- }
- }
- Console.WriteLine("{0}/{1}", n, d);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement