1 条题解
-
0
[信息与未来 2016] 幸运数字(Lucky Numbers) 题解
思路分析
枚举 :若
x % 4 == 0 || x % 7 == 0直接计入;否则不断取最低两位十进制数字判断x % 100 == 44 || x % 100 == 77并令x /= 10。时间复杂度 。参考代码
#include <iostream> using namespace std; bool has44or77(int x) { while (x >= 10) { int t = x % 100; if (t == 44 || t == 77) return true; x /= 10; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; int ans = 0; for (int i = 1; i <= n; ++i) { if (i % 4 == 0 || i % 7 == 0 || has44or77(i)) ++ans; } cout << ans << "\n"; return 0; }
- 1
信息
- ID
- 8535
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者