Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
93516 | 胡海峰老师 | 美丽数 | C | Time Limit Exceeded | 1000 MS | 196 KB | 771 | 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; }