Advertisement
Guest User

lesson3_task3

a guest
Nov 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. package com.company.hw3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class task3 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int x, res = 0;
  10.         x = scanner.nextInt();
  11.  
  12.         for (int i = 2; i <= x; i++) {
  13.             if (x % i == 0) {
  14.                 int div_count = 0;
  15.                 for (int j = 2; j < i; j++) {
  16.                     if (i % j == 0) {
  17.                         div_count += 1;
  18.                     }
  19.                 }
  20.  
  21.                 if (div_count == 0) {
  22.                     res += i;
  23.                 }
  24.             }
  25.         }
  26.  
  27.         System.out.println(res);
  28.  
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement