|
|
вернуться в форумWhy do I get "Time Limit Exceeded"?. Any advise to improve my algorithm? Послано Jay 19 сен 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 |
|
|