Hdu 5585 Numbers

来源:互联网 发布:p2p网贷数据库设计 编辑:程序博客网 时间:2024/06/07 12:00

Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 217    Accepted Submission(s): 151


Problem Description
There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise output "NO".
 

Input
There are multiple test cases, no more than 1000 cases.
For each case,the line contains a integer N.(0<N<1030)
 

Output
For each test case,output the answer in a line.
 

Sample Input
2357
 

Sample Output
YESYESYESNO
 

Source
BestCoder Round #64 (div.2)
 

Recommend
hujie   |   We have carefully selected several similar problems for you:  5589 5588 5584 5583 5582 
 
题目大意:
给一个数N,如果N是2、3或者5的倍数,输出"YES",否则输出"NO".
解体思路:
注意数据范围,用字符串来做。。。比较水
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;#define MM(a) memset(a,0,sizeof(a))typedef long long LL;typedef unsigned long long ULL;const int maxn = 1e5+5;const int mod = 1e4+7;const double eps = 1e-10;const int INF = 0x3f3f3f3f;LL gcd(LL a, LL b){    if(b == 0)        return a;    return gcd(b, a%b);}char str[maxn];int main(){    while(cin>>str)    {        int len = strlen(str);        LL sum = 0;        for(int i=0; i<len; i++)            sum += str[i]-'0';        if(sum%3==0 || (str[len-1]-'0')%2==0 || str[len-1]-'0'==5)            puts("YES");        else            puts("NO");    }    return 0;}


0 0
原创粉丝点击