1 条题解
-
0
的暴力枚举就不说了,这里给一个 的做法。算是给定了 A,B 的扩欧调解
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; // 4x+5y==n 第一组解 int x = -n, y = n; // x+=5 ~ y-=4 调整解,先调到 x 的最小非负整数解 int cnt = (n + (5 - 1)) / 5; // 加几次 5 x += cnt * 5; y -= cnt * 4; // 后续每次调整 x 都不影响,y 能调整的次数就是答案了 if (y < 0) cout << 0 << "\n"; else cout << y / 4 + 1; return 0; }
- 1
信息
- ID
- 110
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 48
- 已通过
- 13
- 上传者