Go to diff to previous submission
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author cteam017 */ public class Fl { /** * @param args the command line arguments */ while (sc.hasNext()) { int counter = 0; line = line.substring(line.indexOf("/") + 1, line.length()); int jmen = n * (n + 1); for (int i = 1;; i++) { if (jmen % i == 0) { counter++; } if (((double) i) / jmen > 1.0 / (n * 2)) { break; } jmen += n; } } } }
--- c5.s786.cteam017.fl.java.0.Fl.java +++ c5.s1014.cteam017.fl.java.0.Fl.java @@ -1,6 +1,18 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + import java.util.Scanner; +/** + * + * @author cteam017 + */ public class Fl { + /** + * @param args the command line arguments + */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); @@ -13,59 +24,20 @@ line = line.substring(line.indexOf("/") + 1, line.length()); int n = Integer.valueOf(line); + + int jmen = n * (n + 1); -// System.out.println(lcm(sc.nextInt(), sc.nextInt())); - - for (int i = n + 1;; i++) { -// System.out.println("1/"+n + " & 1/"+i); - int lcm = getLcm(n, i); -// System.out.println(" lcm = "+lcm); - int nCitatel = lcm / n; - int iCitatel = lcm / i; - -// System.out.println(" --> "+nCitatel+"/"+lcm+" & "+iCitatel+"/"+lcm); - - int resCitatel = nCitatel - iCitatel; - - int vysl = -1; - if (lcm % resCitatel == 0) { - vysl = lcm / resCitatel; - } - - if (vysl != -1) { + for (int i = 1;; i++) { + if (jmen % i == 0) { counter++; -// System.out.println(" !Counter++"); } -// System.out.println("\n\n"); - if (lcm == i) { + if (((double) i) / jmen > 1.0 / (n * 2)) { break; } + jmen += n; } System.out.println(counter); } - - } - - public static int getLcm(int a, int b) { - int starta = a; - int startb = b; - - if (b > a) { - int tmp = a; - a = b; - b = tmp; - } - -// System.out.println("--------------"); -// System.out.println(" lcm("+a+", "+b+")"); -// System.out.println("--------------"); - while (a % b != 0) { - int rest = a % b; - a = b; - b = rest; - } - - return starta * startb / b; } }