fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.math.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main(String[] args) {
  12. Scanner sc = new Scanner(System.in);
  13. int n = sc.nextInt();
  14. int a = sc.nextInt();
  15. int b = sc.nextInt();
  16. int p = sc.nextInt();
  17. int q = sc.nextInt();
  18.  
  19. long ans = 0;
  20.  
  21. int x = n / a;
  22. int y = n / b;
  23. int z = 0;
  24.  
  25.  
  26. long nr = a * b;
  27. int j = 1;
  28.  
  29. while (nr <= n && nr > 0) {
  30. z++;
  31. j++;
  32. nr = a * b * j;
  33. }
  34.  
  35. BigInteger sum = BigInteger.valueOf(0);
  36.  
  37. if (a == b) {
  38. sum = sum.add(BigInteger.valueOf(Math.max(p, q) * x));
  39. }
  40. else if (p > q) {
  41. sum = sum.add(BigInteger.valueOf(x * p));
  42. sum = sum.add(BigInteger.valueOf((y - z) * q));
  43. }
  44. else if (p <= q) {
  45. sum = sum.add(BigInteger.valueOf((x-z) * p));
  46. sum = sum.add(BigInteger.valueOf(y * q));
  47. }
  48.  
  49. System.out.println(sum);
  50. }
  51. }
Runtime error #stdin #stdout #stderr 0.15s 321280KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Ideone.main(Main.java:13)