Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cstring>
  6. #include <map>
  7. #include <set>
  8. #include <vector>
  9. #include <cmath>
  10.  
  11. using namespace std;
  12.  
  13. #define f first
  14. #define s second
  15. #define sz size()
  16.  
  17. const int MAXN = 100 * 100 * 100 + 1;
  18. const double EPS = 0.000000000001;
  19. const int INF = 2 * 1000 * 1000 * 1000;
  20. const int mod = 1000 * 1000 * 1000 + 7;
  21.  
  22. int a, b, k, v, t = 0, l, r, m, cnt[MAXN];
  23. bool used[MAXN];
  24.  
  25. bool check (int p) {
  26. for (int i = a; i <= b - p + 1; i++) {
  27. if (cnt[i + p - 1] - cnt[i - 1] < k)
  28. return false;
  29. }
  30.  
  31.  
  32. return true;
  33. }
  34.  
  35. int main() {
  36. cin >> a >> b >> k;
  37.  
  38. used[0] = used[1] = true;
  39. for (int i = 2; i < 1001; i++) {
  40. if (!used[i])
  41. for (int j = i * i; j <= b; j += i)
  42. used[j] = true;
  43. }
  44.  
  45. for (int i = 0; i <= b; i++)
  46. if (!used[i])
  47. cnt[i] = cnt[i - 1] + 1;
  48. else
  49. cnt[i] = cnt[i - 1];
  50.  
  51. l = 1;
  52. r = b - a + 1;
  53.  
  54. while (t < 22 && l != r) {
  55. t++;
  56. m = (l + r) / 2;
  57. if (check(m))
  58. r = m;
  59. else
  60. l = m + 1;
  61. }
  62.  
  63. if (check(l)) {
  64. cout << l;
  65. return 0;
  66. }
  67.  
  68. if (check(r))
  69. cout << r;
  70. else
  71. cout << -1;
  72.  
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement