CCC '97 S2 - Nasty Numbers

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 16M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

We will call a positive integer nasty if it has at least two pairs of positive integer factors such that the difference of one pair equals the sum of the other pair.

For example, 6 is nasty since 6 \times 1 = 6, 2 \times 3 = 6, 6 - 1 = 2 + 3; and 24 is also nasty since 12 - 2 = 6 + 4.

Write a program which accepts as input a list of positive integers and determines if each one is nasty or not.

Input Specification

The input is a list of positive integers, one per line. The first number in the list is the number of integers to be tested, and is at most 20. The integers to be tested are all less than 32001.

Output Specification

The output should contain one line for each test value. Each line is to contain the test value and whether or not it is nasty.

Sample Input


Sample Output

6 is nasty
24 is nasty
30420 is nasty
10078 is not nasty


  • 8
    d  commented on Nov. 3, 2020, 8:06 p.m.

    This problem only allows the pair (a,b) if a > 0, b > 0, and ab = n.

    Make sure you do not interpret the conditions as a > 0, b > 0, a is a factor, and b is a factor.