ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1086. Cryptography

Why I got Wrong Answer?
Posted by Reg 31 Aug 2003 12:31
#include <fstream.h>
#include <string.h>

const char *Fn_Inp = "p1086.in" ;
const char *Fn_Out = "p1086.out" ;
const char EndLn = '\n' ;
const int MaxN = 16000 ;

typedef
  int TMark[ MaxN ] ;
typedef
  int TPrime[ MaxN ] ;

TMark Mark ;
TPrime Prime ;
long N , K , Tot ;

ifstream Read ( Fn_Inp ) ;
ofstream Write ( Fn_Out ) ;

void Init () {
  int i , j ;

  memset ( Mark , 1 , sizeof ( Mark ) ) ;
  memset ( Prime , 0 , sizeof ( Prime ) ) ;
  Mark[ 1 ] = 0 ;
  for ( i = 2 ; i < MaxN ; i++ )
    if ( Mark[ i ] ) {
      j = i + i ;
      while ( j < MaxN ) {
        Mark[ j ] = 0 ;
        j += i ;
      }
    }
  for ( i = 1 ; i < MaxN ; i++ )
    if ( Mark[ i ] )
      Prime[ Tot++ ] = i ;
}

void Work () {
  long i , Pos ;

  cin >> K ;
  for ( i = 0 ; i < K ; i++ ) {
    cin >> Pos ;
    cout << Prime[ Pos - 1 ] << EndLn ;
  }
}

int main () {
  Init () ;
  Work () ;
  return ( 0 ) ;
}