Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7.     class Program
  8.     {
  9.         static void cubes(ushort n, out ushort a, out ushort b)
  10.     {
  11.         a = 1029;
  12.         b = 1029;
  13.         double mu = 1.0 / 3;
  14.         bool exist = false;
  15.         ushort border = (ushort)((int)Math.Pow(n, mu) + 1);
  16.         for (ushort i = 0; i < border; i++) {
  17.             for (ushort j = 0; j < border; j++) {
  18.                 if ((ushort)((int)Math.Pow(i, 3) + (int)Math.Pow(j, 3)) == n)
  19.                 {
  20.                     a = i;
  21.                     b = j;
  22.                     exist = true;
  23.                     break;
  24.                 }
  25.             }
  26.         }
  27.  
  28.  
  29.     }
  30.         static void Main()
  31.         {
  32.        
  33.         ushort n;
  34.         string input = Console.ReadLine();
  35.         if (!ushort.TryParse(input, out n))
  36.         {
  37.             Console.WriteLine("wrong");
  38.         }
  39.         else {
  40.             ushort a, b;
  41.             cubes(n, out a, out b);
  42.             Console.WriteLine(a == 1029 ? "impossible" : $"{a} {b}");
  43.  
  44.             Console.ReadLine();
  45.         }
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement