Advertisement
Anon2005

descmult

Jul 18th, 2023
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <fstream>
  2. #include <bitset>
  3. using namespace std;
  4.  
  5. ifstream in("descmult.in");
  6. ofstream out("descmult.out");
  7.  
  8. bitset <10000001> ciur;
  9. bitset <10000001> rasp;
  10.  
  11. int d[21], e[21], n;
  12.  
  13. bool verif[1000];
  14.  
  15. int main()
  16. {
  17.     int c, a, b;
  18.     in >> c;
  19.     in >> n >> a >> b;
  20.     if(c == 1)
  21.     {
  22.         unsigned long long rez = 1;
  23.         for(int i = 1; i <= n; i++)
  24.             in >> d[i];
  25.         for(int i = 1; i <= n; i++)
  26.         {
  27.             in >> e[i];
  28.             rez *= (e[i] + 1);
  29.         }
  30.         out << rez;
  31.     }
  32.     else
  33.     {
  34.         for(int i = 1; i <= n; i++)
  35.         {
  36.             in >> d[i];
  37.             verif[d[i]] = 1;
  38.         }
  39.         for(int i = 1; i <= n; i++)
  40.             in >> e[i];
  41.         ciur[0] = ciur[1] = 1;
  42.         for(int i = 4; i <= b; i += 2)
  43.             ciur[i] = 1;
  44.         for(int i = 3; i * i <= b; i += 2)
  45.             if(ciur[i] == 0)
  46.                 for(int j = i * i; j <= b; j += 2 * i)
  47.                     ciur[j] = 1;
  48.         rasp[0] = 1;
  49.         for(int i = 2; i <= b; i++)
  50.             if(ciur[i] == 0)
  51.             {
  52.                 if(i >= 1000 || verif[i] == 0)
  53.                     for(int j = i; j <= b; j += i)
  54.                         rasp[j] = 1;
  55.             }
  56.         for(int i = 1; i <= n; i++)
  57.         {
  58.             ///verific daca d[i] ^ (e[i] + 1) <= b
  59.             int cb = b;
  60.             for(int j = 1; j <= e[i] + 1; j++)
  61.                 cb /= d[i];
  62.             if(cb != 0)
  63.             {
  64.                 int nr = 1;
  65.                 for(int j = 1; j <= e[i] + 1; j++)
  66.                     nr *= d[i];
  67.                 for(int j = nr; j <= b; j += nr)
  68.                     rasp[j] = 1;
  69.             }
  70.         }
  71.         for(int i = a; i <= b; i++)
  72.             if(rasp[i] == 0)
  73.                 out << i << " ";
  74.     }
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement