Back
Close

Prime Squares and Sums

Statement

 Goal

Output the square of the input if it is a prime number, or the sum of each digit in the square of the input.
Input
Line 1: An integer 1 < n <= 100
Output
Output the square of the input (n) if the input is a prime number. If n is not prime, then print the sum of each digit in the square of n.

For example, 17 is a prime number so your output should be 17 squared = 289.
If your input is 12, not prime, then your output the sum of each digit in 12 squared (144) = 1+4+4 = 9.
Constraints
1 < n <= 100
Example
Input
12
Output
9

Game modes
Fastest, Shortest

Test cases
Test 1 Test
Input
12
Output
9

Validator 1 Validator
Input
21
Output
9

Test 2 Test
Input
5
Output
25

Validator 2 Validator
Input
100
Output
1

Test 3 Test
Input
10
Output
1

Validator 3 Validator
Input
5
Output
25

Test 4 Test
Input
21
Output
9

Validator 4 Validator
Input
21
Output
9

Test 5 Test
Input
17
Output
289

Validator 5 Validator
Input
15
Output
9

Test 6 Test
Input
19
Output
361

Validator 6 Validator
Input
19
Output
361

Solution language

Solution

Stub generator input