【HDU3346】Lucky Number(水题模拟)

Categories: 数据结构和算法
Tags: ,
Comments: No Comments
Published on: 2011 年 05 月 12 日

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.

题意:一个幸运数是8的倍数或者各个位和是8的倍数或者各个位的平方和是8的倍数。。。。。
题解:好吧。。。题意就是题解。。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define CLR(arr,val) memset(arr,val,sizeof(arr))
bool is(long long s)
{
	long long sum=0,ssum=0;
	if(s%8==0) return true;
	while(s)
	{
		sum+=s%10;
		ssum+=(s%10)*(s%10);
		s/=10;
	}
	return sum%8==0 || ssum%8==0;
}
int main()
{
	int t;
	
	scanf("%d",&t);
	while(t--)
	{
		long long num;
		cin>>num;
		puts(is(num)?"Lucky number!":"What a pity!");
	}
}

我猜你可能也喜欢:

No Comments - Leave a comment

Leave a comment

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Welcome , today is 星期二, 2017 年 10 月 24 日