ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

fail test 48, what is it?
Posted by Ilya Falko 1 Apr 2018 20:14
package pkg1014;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author niceman
 */
public class App {

    /**
     * @param args the command line arguments
     */
    static long n;

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
                String s = br.readLine();
                for (long i = 0; i < 1000000000; i++)
                {
                    n = i;
                    System.out.println(i+":"+doo(n));
                }

        } catch (IOException ex) {}
    }

    public static String doo(long n){
        long answer = 1;
        int divider = 9;
        if (n == 0)  answer = 10;
        if (isSimple(n) && n > 10) answer = -1;
        else if (n != 0 && n != 1) {
        answer = 0;
        while (n != 1){
            if (n % divider == 0){
                n /= divider;
                if ((isSimple(n) && n > 10) || divider == 1){
                    answer = -1;
                    break;
                }
                answer = answer * 10 + divider;
            }
            else
                divider--;
        }
        }
        if (answer > 10)
           return recursiveReverse(String.valueOf(answer));
        return String.valueOf(answer);
    }
    public static boolean isSimple(long n){
        BigInteger big = BigInteger.valueOf(n);
        return big.isProbablePrime((int) Math.log(n));
    }

    public static String recursiveReverse(String s){
    if (s == null || s.length() <= 1)
        return s;
    return recursiveReverse(s.substring(1)) + s.charAt(0);
    }

}

Edited by author 02.04.2018 19:41