PTA 乙级 1087 有多少不同的值

代码实现:

#include<stdio.h>
#include<stdlib.h>

int main()
{
	int N, *array = (int*)malloc(sizeof(int) * 10334), cnt = 0;

	scanf("%d", &N);
	for (int i = 0; i < 10334; i++)
		array[i] = 0;
	for (int i = 1; i <= N; i++)
		array[i / 2 + i / 3 + i / 5]++;
	for (int i = 0; i < 10334; i++)
		if (array[i] != 0)
			cnt++;
	printf("%d", cnt);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/Gaibb123/article/details/87455557