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 1083. Factorials!!!

Why do I get "Time Limit Exceeded"?. Any advise to improve my algorithm?
Posted by Jay 19 Sep 2015 06:06
public class Factorials {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String str = in.readLine();
        StringTokenizer st = new StringTokenizer(str, " ");

        int n = Integer.parseInt(st.nextToken());
        int k = st.nextToken().length();

        if (n >= 1 && n <= 10) {
            if (k >= 1 && k <= 20) {
                int limite= n % k, total = n, res= 0, i = 1;
                do {
                    res= (n - (k * i));
                    if (res== 0) {
                        System.out.print(total);
                        return;
                    }
                    total *= res;
                    i++;
                } while (res!= limite);
                System.out.print(total);
            }
        }
    }
}

Edited by author 19.09.2015 06:20