Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by carado ( 16 years ago )
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <math.h>

bool isPrimary(int a);

int main(int argc, char *argv[])
{
 if (argc != 2)
 {
  std::cerr<<"Usage : "<<argv[0]<<" <end> n";
  return (EXIT_FAILURE);
 }
 int a=2;
 while (a <= strtol(argv[1],NULL,10))
 {
  if (isPrimary(a))
   std::cout<<a<<std::endl;
  a++;
 }
 return (EXIT_SUCCESS);
}

bool isPrimary(int a)
{
 static std::vector<int> primarys;
 if (primarys.size() == 0)
  primarys.push_back(2);
 for (int i=0; pow(primarys[i], 2)<=a; i++)
 {
  if (a%primarys[i]==0)
   return false;
 }
 primarys.push_back(a);
 return true;
}

 

Revise this Paste

Your Name: Code Language: