title: memoization and prime number generation using sieve of eratosthenes using maps
body: <pre><code>#include&lt;iostream&gt; 
  #include&lt;map&gt; 
  #include&lt;algorithm&gt; 
  #include&lt;math.h&gt;
  using namespace std ; 
  map&lt; long long int , long long int &gt; prim ;
  map&lt; long long int , long long int &gt;::iterator it ;
  
  int c, counter, check ;
  long long int b ;
  int prime( long long int t)
  {  
      if( t==1 )
      {
          prim[1] = 1 ;
          counter = 1 ;
          it=prim.begin() ;
          //cout&lt;&lt; it-&gt;second  ;
          return 1 ;    
       }
       else
       {
           check = -1 ;
           long long int f ; 
           f= int(sqrt(t)) ; // could create prob
           for(  it=prim.begin()  ; it!= prim.end() || it-&gt;second &lt;=f ;  it++)
           {  
               if( (t % (it-&gt;second))==0  &amp;&amp;  it-&gt;second != 1 )
               {
                   cout &lt;&lt; "not prime " &lt;&lt; "\n" ;
                   check = 0 ;
                   // not prime 
                   break ; 
               }        
           }
  
           if(check==-1)
           { 
               //  prime ;
               counter ++ ; 
               prim[counter] = t ; 
               return 1 ;
           }  
  
           else if(check==0)
               return 0 ;
  
       } 
   }  
  
   int main()
   {
       int check2 ;
       check2 = 1  ; // value set 1 to call it prime 
  
       cout&lt;&lt; "input no ";
  
       cout&lt;&lt;"\n";
  
       cin &gt;&gt;b ;
  
       for( long long  int z=1 ;z &lt;=int(sqrt(b)); z++  )
       {
           c = prime(z) ;
           //cout&lt;&lt;"z is "&lt;&lt;z &lt;&lt;"\n";
  
           if ( c==1  &amp;&amp; z!=1 )
           {
               if((b%z) == 0)
               {
                   //cout&lt;&lt; "not prime " ; 
                   check2 = 0 ;
                   break ;  
               }
           }
      }
  
      if(check2!=0)
      {
          cout&lt;&lt;"\n";
          cout&lt;&lt; "prime"  ;
      }
      else 
          cout&lt;&lt; "not prime " ;  
  
      for(  it=prim.begin()  ; it!= prim.end() ;  it++)
      { 
          cout&lt;&lt;"\n" ; 
          cout&lt;&lt; it-&gt;first ; 
  
          cout&lt;&lt; it-&gt;second ; 
          cout&lt;&lt; " \n"  ;
  
      }
  
      return 0 ;
  }
  </code></pre>
  
  <p>well i am having problems with numbers like above 200  and that are prime . the     program does not execute properly  giving unexpected values .</p>
  
  <p>if you guys could tell me about the errors or better ways to generate a map of primes please do ! </p>