hdu 5585 水题 Numbers 2015.11.28 bestcoder 1001

本文介绍了一种快速判断大数(长度最多为30)是否能被2、3或5整除的方法。通过检查个位数及各位数字之和来实现高效判断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:给一个长度最多为30的数,问是否能被2,3或者5整除

思路:按照字符串存储,判断最后一个数是不是2的倍数、5,以及判断各个位相加是否能被3整除

Numbers

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


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

<pre name="code" class="cpp">#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <time.h>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int INF=0x7fffffff;
const int MAX_N=10000;

//long long n;
char A[100];
int main(){
    while(scanf("%s",&A)!=EOF){
        if(A[strlen(A)-1]=='0'||A[strlen(A)-1]=='5'){
            printf("YES\n");
            continue;
        }
        if((A[strlen(A)-1]-'0')%2==0){
            printf("YES\n");
            continue;
        }
        int ans=0;
        for(int i=0;i<strlen(A);i++){
            ans+=A[i]-'0';
        }
        if(ans%3==0){
            printf("YES\n");
            continue;
        }

        else printf("NO\n");
    }
    return 0;
}

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值