10394  Twin Primes
Moderator: Board moderators

 Learning poster
 Posts: 94
 Joined: Sat Oct 05, 2002 5:34 pm
 Location: CS  AIUB, Dhaka, Bangladesh.
 Contact:
10394
i got this WA. can any1 tell the some critical inputs?
Last edited by Sajid on Sat Oct 25, 2003 6:53 pm, edited 1 time in total.
Sajid Online: www.sajidonline.com

 Learning poster
 Posts: 94
 Joined: Sat Oct 05, 2002 5:34 pm
 Location: CS  AIUB, Dhaka, Bangladesh.
 Contact:
thanx for help
but i m facing problem with the array size, as i m using Turbo C++ 3.0. and so i cant see the value for the all input. then, what can i do now? plz, help...
but i m facing problem with the array size, as i m using Turbo C++ 3.0. and so i cant see the value for the all input. then, what can i do now? plz, help...
Sajid Online: www.sajidonline.com

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
but you still can do it in this way:
create algorithm working with array i.e. 1000 elements and before sending solution create bigger array and send such solution. I did problems in this way in BC3.1 long time ago and it's work other method is using less memory consuming algorithms )
Dominik
create algorithm working with array i.e. 1000 elements and before sending solution create bigger array and send such solution. I did problems in this way in BC3.1 long time ago and it's work other method is using less memory consuming algorithms )
Dominik
If you really want to get Accepted, try to think about possible, and after that  about impossible ... and you'll get, what you want ....
Born from ashes  restarting counter of problems (800+ solved problems)
Born from ashes  restarting counter of problems (800+ solved problems)

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
Jalal, I don't think so ....
If you run program under Windows / DOS you know how much memory you use ... Then If you increase limits, you know memory usage, i.e.
if your table has 1000 elements, and program use 100kB ram, then after change limit to 100000, than your program should use 10MB ram ....
And you know how is maximal limit for your arrays
Other way is counting memory self
Dominik
If you run program under Windows / DOS you know how much memory you use ... Then If you increase limits, you know memory usage, i.e.
if your table has 1000 elements, and program use 100kB ram, then after change limit to 100000, than your program should use 10MB ram ....
And you know how is maximal limit for your arrays
Other way is counting memory self
Dominik
If you really want to get Accepted, try to think about possible, and after that  about impossible ... and you'll get, what you want ....
Born from ashes  restarting counter of problems (800+ solved problems)
Born from ashes  restarting counter of problems (800+ solved problems)
10394 Bad output or WA? PLZ help!
Hi,
This is my code, it is very simple but it finishes calculationes within the alloted time so thats just fine for me but im getting WA and i dont know why!!!!
[cpp]
#include <fstream.h>
#include <math.h>
/*Returns one if the number is prime, else it returns zero*/
int isPrime(int n)
{
int root = sqrt(n);
for(int i=3; i<root; i+=2)
if(n % i == 0)
return 0;
return 1;
}
void main()
{
long i=0,j;
long calc[100000][2]={3,5};
char *table = new char[18409201];
//ifstream cin;
//cin.open("texto.txt"); //just for testing
/*This is the core of the algorithm*/
for( i=3; i<=4290; i+=2)
if(isPrime(i))
for(j=i+i1; j<18409201; j+=i)
table[j] = 0;
/*We now store ALL the twin primes*/
for(j=4,i=1; j<=18409201; j+=6)
if(table[j]!=0 && table[j+2]!=0)
{
calc[0]=j+1;
calc[1]=j+3;
i++;
}
/*Get the input and give the output*/
while(cin>>i)
cout<<"("<<calc[i1][0]<<", "<<calc[i1][1]<<")"<<endl;
}
[/cpp]
Could some of you guys please help me, I tested it with all the inputs that I culd imagine. is it something about the sapce ASCII32? omg so confused
This is my code, it is very simple but it finishes calculationes within the alloted time so thats just fine for me but im getting WA and i dont know why!!!!
[cpp]
#include <fstream.h>
#include <math.h>
/*Returns one if the number is prime, else it returns zero*/
int isPrime(int n)
{
int root = sqrt(n);
for(int i=3; i<root; i+=2)
if(n % i == 0)
return 0;
return 1;
}
void main()
{
long i=0,j;
long calc[100000][2]={3,5};
char *table = new char[18409201];
//ifstream cin;
//cin.open("texto.txt"); //just for testing
/*This is the core of the algorithm*/
for( i=3; i<=4290; i+=2)
if(isPrime(i))
for(j=i+i1; j<18409201; j+=i)
table[j] = 0;
/*We now store ALL the twin primes*/
for(j=4,i=1; j<=18409201; j+=6)
if(table[j]!=0 && table[j+2]!=0)
{
calc[0]=j+1;
calc[1]=j+3;
i++;
}
/*Get the input and give the output*/
while(cin>>i)
cout<<"("<<calc[i1][0]<<", "<<calc[i1][1]<<")"<<endl;
}
[/cpp]
Could some of you guys please help me, I tested it with all the inputs that I culd imagine. is it something about the sapce ASCII32? omg so confused
confused
can any of you guys tellme whats wrong with my code,
im getting WA
[cpp]
#include <fstream.h>
#include <math.h>
/*Returns one if the number is prime, else it returns zero*/
int isPrime(int n)
{
int root = sqrt(n);
for(int i=3; i<root; i+=2)
if(n % i == 0)
return 0;
return 1;
}
void main()
{
long i=0,j;
long calc[100000][2]={3,5};
char *table = new char[18409201];
//ifstream cin;
//cin.open("texto.txt"); //just for testing
/*This is the core of the algorithm*/
for( i=3; i<=4290; i+=2)
if(isPrime(i))
for(j=i+i1; j<18409201; j+=i)
table[j] = 0;
/*We now store ALL the twin primes*/
for(j=4,i=1; j<=18409201; j+=6)
if(table[j]!=0 && table[j+2]!=0)
{
calc[0]=j+1;
calc[1]=j+3;
i++;
}
/*Get the input and give the output*/
while(cin>>i)
cout<<"("<<calc[i1][0]<<", "<<calc[i1][1]<<")"<<endl;
}
[/cpp]
im getting WA
[cpp]
#include <fstream.h>
#include <math.h>
/*Returns one if the number is prime, else it returns zero*/
int isPrime(int n)
{
int root = sqrt(n);
for(int i=3; i<root; i+=2)
if(n % i == 0)
return 0;
return 1;
}
void main()
{
long i=0,j;
long calc[100000][2]={3,5};
char *table = new char[18409201];
//ifstream cin;
//cin.open("texto.txt"); //just for testing
/*This is the core of the algorithm*/
for( i=3; i<=4290; i+=2)
if(isPrime(i))
for(j=i+i1; j<18409201; j+=i)
table[j] = 0;
/*We now store ALL the twin primes*/
for(j=4,i=1; j<=18409201; j+=6)
if(table[j]!=0 && table[j+2]!=0)
{
calc[0]=j+1;
calc[1]=j+3;
i++;
}
/*Get the input and give the output*/
while(cin>>i)
cout<<"("<<calc[i1][0]<<", "<<calc[i1][1]<<")"<<endl;
}
[/cpp]