Advertisement
a53

masterplace002_OFICIALA

a53
Mar 14th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include "fstream"
  2.  
  3. using namespace std;
  4.  
  5. ifstream cin("masterpiece002.in");
  6. ofstream cout("masterpiece002.out");
  7.  
  8. int stiva[505050];
  9. bool plan[1001][1001];
  10.  
  11. int caut(int st, int dr, int x){
  12. while(st <= dr){
  13. int m = ((st + dr) >> 1);
  14. if(x >= stiva[m])
  15. st = m + 1;
  16. else
  17. dr = m - 1;
  18. }
  19. return st;
  20. }
  21.  
  22. int modul(int x1, int x2, int y1, int y2){
  23. int d1 = x1 - x2;
  24. int d2 = y1 - y2;
  25.  
  26. if(d1 < 0)
  27. d1 = -d1;
  28. if(d2 < 0)
  29. d2 = -d2;
  30.  
  31. return (plan[d1][d2] == 0);
  32. }
  33. void ciur(){
  34. for(int i=2 ; i<=500 ; ++i)
  35. if(plan[i][0] == 0)
  36. for(int j=(i<<1) ; j<=1000 ; j+=i)
  37. plan[j][0] = 1;
  38.  
  39. for(int i=2 ; i<=1000 ; ++i)
  40. if(plan[i][0] == 0){
  41. int k = i;
  42. while(k <= 1000){
  43. int p = i;
  44. while(p <= 1000)
  45. plan[k][p] = 1, p += i;
  46. k += i;
  47. }
  48. }
  49.  
  50. for(int i=0 ; i<=1000 ; ++i)
  51. plan[i][0] = plan[0][i] = 1;
  52.  
  53. plan[1][0] = plan[0][1] = 0;
  54. }
  55.  
  56. int main(){
  57. int x1, x2, y1, y2, rez = 0;
  58. ciur();
  59. while(cin >> x1 >> y1 >> x2 >> y2){
  60. if(modul(x1, x2, y1, y2)){
  61. int lungime = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  62. if(lungime >= stiva[rez])
  63. stiva[++rez] = lungime;
  64. else
  65. stiva[caut(1, rez, lungime)] = lungime;
  66. }
  67. }
  68. cout << rez;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement