Run ID:93516
提交时间:2024-10-17 15:33:29
#include <stdio.h> // 计算在max范围内的美丽数的数量 int countBeautiful(int max) { int count = 0; for (int i = 1; i <= max; i++) { if (i % 3 == 0 || i % 5 == 0) { count++; } } return count; } int main() { int N; while (scanf("%d", &N) != EOF) { int left = 1, right = 100000, mid; int beautifulNum = 0; while (left <= right) { mid = left + (right - left) / 2; int count = countBeautiful(mid); if (count < N) { left = mid + 1; } else { beautifulNum = mid; right = mid - 1; } } printf("%d\n", beautifulNum); } return 0; }