Problem B
Luhn's Checksum Algorithm

In 1954, Hans Peter Luhn, a researcher at IBM, filed a
patent describing a simple checksum algorithm for numbers
written as strings of base-
Given a number
-
Starting at the right end of
, transform every second digit (i.e., ) as follows:-
multiply
by -
if
consists of more than one digit, i.e., is greater than 9, add these digits together; this will always produce a single-digit number
-
-
Add up all the digits of
after the transformation step. If the resulting sum is divisible by , passes the Luhn checksum test. Otherwise, fails the Luhn checksum test.
For example, consider the number
and since
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input
The first line of input contains a single integer
Output
For each test case, output a single line containing “PASS” if the number passes the Luhn checksum test, or “FAIL” if the number fails the Luhn checksum test.
Sample Input 1 | Sample Output 1 |
---|---|
3 00554 999 1234567890123411 |
PASS FAIL PASS |