__rain1

Untitled

Jun 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.lang.Math;
  2.  
  3. class MosaicNumber {
  4.  
  5.     public static void main (String[] args) {
  6.         int n = 36;
  7.         System.out.println(getMosaicNumber(n));
  8.     }
  9.    
  10.     public static int getMosaicNumber(int n){
  11.  
  12.         int result = 1;
  13.  
  14.         for(int i = 2; i < n ; i++){
  15.  
  16.             if(n%i == 0 && isPrime(i)){
  17.                 //System.out.println("here");
  18.                 int power = 1;
  19.                 double current = n/i ;
  20.                 while(true){
  21.                     current = current/i;
  22.                     if(current == Math.floor(current)){
  23.                         power++;
  24.                     }else{
  25.                         result *= i*power;
  26.                         break;
  27.                     }
  28.                 }
  29.             }
  30.         }//close loop
  31.        
  32.  
  33.  
  34.         return result;
  35.     }
  36.    
  37.     public static boolean isPrime(int n){
  38.        
  39.         if(n==2) return true;
  40.        
  41.         for(int i = 2; i<n ; i++){
  42.             if(n%i == 0){
  43.                 return false;
  44.             }
  45.         }//close loop
  46.        
  47.         return true;
  48.     }
  49. }
Add Comment
Please, Sign In to add comment