#C2533. Credit Card Number Validation Using the Luhn Algorithm

    ID: 45860 Type: Default 1000ms 256MiB

Credit Card Number Validation Using the Luhn Algorithm

Credit Card Number Validation Using the Luhn Algorithm

In this problem, you are required to determine whether a given credit card number is valid using the Luhn algorithm. The Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers.

The algorithm works as follows: Let the credit card number be represented as a string of digits. Starting from the rightmost digit, every second digit is doubled. If the result of this doubling is greater than 9, then subtract 9 from it. Sum all the resulting digits along with the untouched digits. If the total sum is divisible by 10, then the credit card number is considered valid; otherwise, it is invalid.

For example, consider the number :\(4532015112830366\):

  • Double every second digit from the right.
  • If doubling any digit results in a number greater than 9, subtract 9 from it.
  • Add all the processed digits.
  • If the sum modulo 10 equals 0, the card is valid.

You must read the credit card number from the standard input and output the result (True or False) to the standard output.

inputFormat

The input consists of a single line containing a credit card number as a string of digits.

Example: 4532015112830366

outputFormat

Output a single line: True if the credit card number is valid according to the Luhn algorithm, or False otherwise.

## sample
4532015112830366
True