Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Кварталы
  8. {
  9.     class Program
  10.     {
  11.         static public int QuarterCalculation(int x, int y)
  12.         {
  13.             if (x == y) //||(x % y == 0 || y % x == 0))
  14.                 return x;//Math.Max(x, y);
  15.             var d = Math.Min(x, y);
  16.             while (x % d != 0 || y % d != 0)
  17.                 d--;
  18.             if (d == 1)
  19.                 return x + y - 1;
  20.             else
  21.             {
  22.                 x = x / d;
  23.                 y = y / d;
  24.                 return (x + y - 1) * d;
  25.             }
  26.  
  27.         }
  28.    
  29.         static void Main(string[] args)
  30.         {
  31.             var str = "";
  32.             var str1 = "";
  33.             var str2 = "";
  34.             int x, y;
  35.             int i = 0;
  36.             str = Console.ReadLine();
  37.             while (str[i] != ' ')
  38.             {
  39.                 str1 += str[i];
  40.                 i++;
  41.             }
  42.             i++;
  43.             while (i < str.Length)
  44.             {
  45.                 str2 += str[i];
  46.                 i++;
  47.             }
  48.             x = int.Parse(str1) - 1;
  49.             y = int.Parse(str2) - 1;
  50.             //Console.WriteLine(x);
  51.             //Console.WriteLine(y);
  52.             Console.WriteLine(QuarterCalculation(x, y));
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement