Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- class MosaicNumber {
- public static void main (String[] args) {
- int n = 36;
- System.out.println(getMosaicNumber(n));
- }
- public static int getMosaicNumber(int n){
- int result = 1;
- for(int i = 2; i < n ; i++){
- if(n%i == 0 && isPrime(i)){
- //System.out.println("here");
- int power = 1;
- double current = n/i ;
- while(true){
- current = current/i;
- if(current == Math.floor(current)){
- power++;
- }else{
- result *= i*power;
- break;
- }
- }
- }
- }//close loop
- return result;
- }
- public static boolean isPrime(int n){
- if(n==2) return true;
- for(int i = 2; i<n ; i++){
- if(n%i == 0){
- return false;
- }
- }//close loop
- return true;
- }
- }
Add Comment
Please, Sign In to add comment