package laba3;

import java.util.Scanner;

public class example5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Введите количество чисел для суммы: ");
        int n = scanner.nextInt();

        // ===== ВЕРСИЯ 1: цикл for =====
        System.out.println("\nВерсия с циклом for:");
        int count = 0;
        int sum = 0;
        int number = 1;

        for (; count < n; number++) {
            if (number % 5 == 2 || number % 3 == 1) {
                System.out.print(number + " ");
                sum += number;
                count++;
            }
        }

        System.out.println("\nСумма: " + sum);

        // ===== ВЕРСИЯ 2: цикл while =====
        System.out.println("\nВерсия с циклом while:");
        count = 0;
        sum = 0;
        number = 1;

        while (count < n) {
            if (number % 5 == 2 || number % 3 == 1) {
                System.out.print(number + " ");
                sum += number;
                count++;
            }
            number++;
        }

        System.out.println("\nСумма: " + sum);

        scanner.close();
    }
}