Advertisement
Virtual_Universe

good

Apr 26th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. namespace goodNumber
  4. {
  5.     class MainClass
  6.     {
  7.         public static List<long> d = new List<long> {};
  8.         public static bool prost(long x){
  9.             long c = (long)Math.Sqrt(x);
  10.  
  11.             for(long i = 2; i <= c;i++)
  12.                 if (x % i == 0)
  13.                     return false;
  14.            
  15.             return true;
  16.         }
  17.         public static void Main ()
  18.         {
  19.            
  20.             string[] num = Console.ReadLine().Split(' ');
  21.             long n = long.Parse(num[0]);
  22.             long k = long.Parse(num[1]);
  23.             bool f = false;
  24.             //-----------------------------------------------
  25.  
  26.             for (long i = 2; i <= n; i++) {
  27.                 if (n % i == 0 && (prost (i) || (i == k * k && f == true))) {
  28.                     if (i != k) {
  29.                         while (n % i == 0) {///есть подозрения что это я на говнокодил и можно прже(этот вайл)
  30.                             n = (long)n / i;
  31.                             d.Add (i);
  32.                         }
  33.                     }
  34.                     else
  35.                         f = true;
  36.                 }
  37.                 if(n <= 1)
  38.                     break;
  39.             }
  40.             d.Sort();
  41.             //-----------------------------------------------
  42.             if (n > 1)
  43.                 Console.Write (-1);
  44.             else
  45.                 for(int j = 0;j<d.Count;j++){
  46.                     Console.Write (d [j]);
  47.                     Console.Write (" ");
  48.                 }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement