思路:
暴力枚举。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int n, m, x, y; 4 bool check(int x, unordered_map<int, int>& m) 5 { 6 for (auto it : m) 7 { 8 int a = it.first, b = it.second; 9 if ((a + x - 1) / x != b) return false; 10 } 11 return true; 12 } 13 int main() 14 { 15 while (cin >> n >> m) 16 { 17 unordered_map<int, int> mp; 18 for (int i = 0; i < m; i++) 19 { 20 cin >> x >> y; 21 mp[x] = y; 22 } 23 int ans = -1; 24 bool flg = true; 25 for (int i = 1; i <= 100; i++) 26 { 27 if (check(i, mp)) 28 { 29 if (ans != -1 && (n + i - 1) / i != ans) 30 { 31 flg = false; break; 32 } 33 else ans = (n + i - 1) / i; 34 } 35 } 36 if (flg && ans != -1) cout << ans << endl; 37 else cout << -1 << endl; 38 } 39 return 0; 40 }