Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PrimePairs {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstStart = Integer.parseInt(scanner.nextLine()),
- secondStart = Integer.parseInt(scanner.nextLine()),
- firstDiff = Integer.parseInt(scanner.nextLine()),
- secondDiff = Integer.parseInt(scanner.nextLine());
- for (int i = firstStart; i <= firstStart + firstDiff; i++) {
- for (int j = secondStart; j <= secondStart + secondDiff; j++) {
- boolean isFirstPrime = true, isSecondPrime = true;
- for (int k = 2; k <= Math.sqrt(i); k++) {
- if (i % k == 0) {
- isFirstPrime = false;
- break;
- }
- }
- for (int k = 2; k <= Math.sqrt(j); k++) {
- if (j % k == 0) {
- isSecondPrime = false;
- break;
- }
- }
- if (isFirstPrime && isSecondPrime) {
- System.out.printf("%d%d\n", i, j);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement