Tuesday, June 14, 2016

SPOJ Challenges

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      #include <iostream>
      #include <cmath>
      using namespace std;
       
      int main() {
          // your code goes here
          auto t = 0;
          std::cin >> t;
          
          for (auto c = 0; c < t; ++c)
          {
              auto s = 0, e = 0;
              std::cin >> s >> e;
       
              auto isprime = true;
              auto i = 0;
       
              for (i = s; i <= e; ++i)
              {
                  if (i == 1) continue;
       
                  isprime = true;
                  int x = (int)std::sqrt(i);
       
                  for (int f = 2; f <= x; ++f)
                  {
                      if (i % f == 0)
                      {
                          isprime = false;
                          break;
                      }
                  }
       
                  if (isprime)
                  {
                      std::cout << i << std::endl;
                  }
              }
          }
          return 0;
      } 
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      #include <iostream>
      using namespace std;
       
      int main() {
       // your code goes here
       auto x = 0;
       while(std::cin >> x)
       {
        if(x == 42) break;
        std::cout << x << std::endl;
       }
       return 0;
      } 
      

No comments:

Post a Comment