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

Solution
Posted by Hamidreza Hosseinkhani 30 May 2011 02:06
/******************************* In The Name Of God ********************************
Problem ID: 1086 - Cryptography    (http://acm.timus.ru/problem.aspx?space=1&num=1086)
Time Limit: 2.0 sec
Memory Limit: 16 MB
Author: Hamidreza Hosseinkhani    (hosseinkhani@live.com)
***********************************************************************************/

#include <iostream>
using namespace std;
#include <cmath>

bool prime( float num )
{
    for ( int i = 2 ; i <= sqrt( num ) ; i++ )
        if ( !( (int) num % i ) )    return false;
    return true;
}

int main()

{
    //ifstream cin( "in.txt" );
    //ofstream cout( "out.txt" );

    int k, n, *list, max = 0;
    cin >> k;
    list = new int [k];
    for ( int i = 0 ; i < k ; i++ )    {
                        cin >> list[i];
                        if ( list[i] > max )    max = list[i];
                    }
    int *primes = new int [max];
    for ( int i = 2, c = 0 ; c < max ; i++ )
        if ( prime( i ) )    {
                        primes[c] = i;
                        c++;
                    }
    for ( int i = 0 ; i < k ; i++ )
        cout << primes[list[i] - 1] << endl;
    return EXIT_SUCCESS;
}
Re: Solution
Posted by AterLux 30 May 2011 14:04
1) Your solution takes too long time to precalculations. Try do it faster ;)
2) do not public your AC solutions - show respect to authors who have not solved it yet

Edited by author 30.05.2011 14:05
Re: Solution
Posted by Frankie 26 Nov 2011 09:09
lol why would you use live.com? :D
Re: Solution
Posted by Kaykobad Reza 26 Sep 2015 13:32
Totally a show off.

Edited by author 26.09.2015 13:34

Edited by author 26.09.2015 13:34