fork download
  1. import java.util.Arrays;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. int v = 115;
  6. int[] primes = getPrimes(v + 1);
  7. for (int i = 0; primes[i] <= Math.sqrt(v); i++) {
  8. int n = primes[i];
  9. if (v % n == 0) {
  10. int m = v / primes[i];
  11. if (Arrays.binarySearch(primes, m) >= 0) {
  12. System.out.println(n + ", " + m);
  13. break;
  14. }
  15. }
  16. }
  17. }
  18.  
  19. static int[] getPrimes(int count) {
  20. int[] a = new int[count];
  21. a[0] = -1;
  22. a[1] = -1;
  23. int c = 0;
  24. for (int i = 0; i < a.length; i++) {
  25. if (a[i] != -1) {
  26. c += 1;
  27. for (int j = i + i; j < a.length; j += i) {
  28. a[j] = -1;
  29. }
  30. }
  31. }
  32. int b[] = new int[c];
  33. int j = 0;
  34. for (int i = 0; i < a.length; i++) {
  35. if (a[i] == 0) {
  36. b[j] = i;
  37. j += 1;
  38. }
  39. }
  40. return b;
  41. }
  42. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
5, 23