HDU3346: Lucky Number

Source: Internet
Author: User

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;
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.