Advertisement
Guest User

Untitled

a guest
Apr 30th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solution {
  6.  
  7.     public static void main(String args[]) {
  8.         Scanner in = new Scanner(System.in);
  9.         int n = in.nextInt();
  10.         int a = 0;
  11.         int sum = 0;
  12.         for (int i=2;i<Math.sqrt(n);i++) {
  13.             if (n%i==0) {
  14.                 a++;
  15.                 break;
  16.             }
  17.         }
  18.         if (a==0) {
  19.             System.out.println(n*n);
  20.         }
  21.         else {
  22.             n=n*n;
  23.             while(n>0) {
  24.                 sum+=n%10;
  25.                 n-=n%10;
  26.                 n/=10;
  27.             }
  28.             System.out.println(sum);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement