[HDU] [5585] Numbers

Problem Description

Loading...

Problem Analysis

I searched for ages and still couldn’t find where the original problem came from
so I had to name it this way

I felt this problem was still worth writing about
pretty interesting

The key here is the constraint on N
obviously it’s a relatively large number

So we still have to simulate it with strings
and then when checking divisibility by 2, 3 and 5 there are simpler tests

First, the check for 2 and 5
you only need to look at the last character of the string
that is, the last digit of the number

For 3, though, I still couldn’t think of a better test
so I used that theorem: if the sum of the digits is divisible by 3
then the number itself is divisible by 3

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
#include<string.h>
int main() {
	char s[100];
	int l,i;
	__int64 m;
	while(scanf("%s",s)!=EOF) {
		l=strlen(s);
		if((s[l-1]-'0')%2==0)
			printf("YES\n");
		else if(s[l-1]=='0'||s[l-1]=='5')
			printf("YES\n");
		else {
			for(i=m=0; i<l; i++) {
				m=m+s[i]-'0';
			}
			if(m%3==0)
				printf("YES\n");
			else
				printf("NO\n");
		}
	}
	return 0;
}

No idea whether the problem link is even reachable…
And the senior wouldn’t tell me where the problem came from either…
-.-
so inconsiderate

Problem link: 【HDU】[5585]Numbers

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...