Hdu 5585 Numbers

简介:

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
 
 
2 3 5 7
 

Sample Output
 
 
YES YES YES NO
 

Source
 

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


目录
相关文章
|
7月前
|
机器学习/深度学习 存储 人工智能
HDU - 5912——Fraction
HDU - 5912——Fraction
|
Java 文件存储
hdu1128 Self Numbers
hdu1128 Self Numbers
37 0
|
机器学习/深度学习
hdu1059Dividing
题意:有6种石头,价值分别是1,2,3,4,5,6   每种有若干,作为输入数据。问能否把这些石头按照价值均分? 分析:多重背包问题。 代码: View Code 1 #include 2 #include 3 #include 4 using namespace...
874 0
hdu 1298 T9
点击打开链接hdu 1298 题意:题目说的是在那遥远的星球有一款叫诺基亚的手机,键盘采用题目的图的样式。给定n个单词的出现的概率,规定是相加的比如hell出现为4,hello概率为3则hell的概率为7。
758 0