Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. ifstream in("puteri4.in");
  9. ofstream out("puteri4.out");
  10.  
  11. vector<int> prime;
  12.  
  13. inline double radical(double x, double ord)
  14. {
  15.     return pow(x, 1.0 / ord);
  16. }
  17.  
  18. unsigned long long f(unsigned long long x, unsigned long long e)
  19. {
  20.     if(x <= 0)
  21.         return 0;
  22.     unsigned long long ret = 1;
  23.     unsigned long long r;
  24.     for(auto p:prime)
  25.     {
  26.         if(p >= e)
  27.             break;
  28.         r = radical(x, p);
  29.         if(r > 1)
  30.         {
  31.             ret += r;
  32.             ret -= f(r, p);
  33.         }
  34.     }
  35.     return ret;
  36. }
  37.  
  38. unsigned long long query(double x, double y)
  39. {
  40.     unsigned long long ret = f(y, 60) - f(x-1, 60);
  41.     return ret;
  42. }
  43.  
  44. void ciur()
  45. {
  46.     const int maxPut = 65;
  47.     static bool compus[maxPut + 1];
  48.     for(int i = 2; i <= maxPut; ++i)
  49.         for(int j = i * i; j <= maxPut; j += i)
  50.             compus[j] = true;
  51.     for(int i = 2; i <= maxPut; ++i)
  52.         if(compus[i] == false)
  53.             prime.push_back(i);
  54. }
  55.  
  56. int main()
  57. {
  58.     ciur();
  59.     int t;
  60.     double x, y;
  61.     in >> t;
  62.     for(int i = 1; i <= t; ++i)
  63.     {
  64.         in >> x >> y;
  65.         out << query(x, y) << "\n";
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement