Problem Description
To Chinese people, 8 is a lucky number. Now your task is to judge if a number is lucky.
We say a number is lucky if it's a multiple of 8, or the sum of digits that make up the number is a multiple of 8, or the sum of every digit's square is a multiple of 8.
Input
The first line contains an integer stands for the number of test cases.
Each test case contains an integer n (n> = 0 ).
Output
For each case, output "Lucky number !" If the number is luky, otherwise output "What a pity !".
Sample Input
2
0
8
Sample Output
Lucky number!
Lucky number!
At the beginning, I did not notice the sum of the values of each number.
[Cpp]
# Include <stdio. h>
Int main ()
{
Int t;
Scanf ("% d", & t );
While (t --)
{
Int a, flag = 0, sum1 = 0, sum2 = 0;
Scanf ("% d", & );
If (a % 8 = 0)
Flag = 1;
Else
{
While ()
{
Sum1 + = a % 10;
Sum2 + = (a % 10) * (a % 10 );
A/= 10;
}
If (sum1% 8 = 0)
Flag = 1;
Else if (sum2% 8 = 0)
Flag = 1;
}
If (flag)
Printf ("Lucky number! \ N ");
Else
Printf ("What a pity! \ N ");
}
Return 0;
}
# Include <stdio. h>
Int main ()
{
Int t;
Scanf ("% d", & t );
While (t --)
{
Int a, flag = 0, sum1 = 0, sum2 = 0;
Scanf ("% d", & );
If (a % 8 = 0)
Flag = 1;
Else
{
While ()
{
Sum1 + = a % 10;
Sum2 + = (a % 10) * (a % 10 );
A/= 10;
}
If (sum1% 8 = 0)
Flag = 1;
Else if (sum2% 8 = 0)
Flag = 1;
}
If (flag)
Printf ("Lucky number! \ N ");
Else
Printf ("What a pity! \ N ");
}
Return 0;
}