How many different values (20 points) PAT B1087 has

Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/1038429191091781632

Description Title
When the natural number n sequentially capturing 1,2,3, ......, N, the equation ⌊n / 2⌋ + ⌊n / 3⌋ + ⌊n / 5⌋ how many different values are? (Note: ⌊x⌋ to rounding function, x represents no more than the maximum natural number, i.e. the integer part of x.)

Input
Input Given a positive integer N (2≤N≤10 ^ 4).

Output
number of distinct values in the output plane equation takes the question in a row.

Sample input
2017

Sample Output
1480

Code

#include <cstdio>
int main() {
	int n, h[100010] = {0}, num = 0, sum;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++) {
		sum = i / 2 + i / 3 + i / 5;
		if(h[sum] == 0)
			num++;
		h[sum] = 1;
	}
	printf("%d\n", num);

}
Published 327 original articles · won praise 12 · views 20000 +

Guess you like

Origin blog.csdn.net/Rhao999/article/details/105229224