Thanks to u. Your I/O really helped me. I mistake just at that point. After removing that from my code, I got AC.




Moderator: Board moderators
and think 257 263 269 are a sequence of 3 uni-distance primes; but since 251 are one the members of 6 diffrence sequence and it is not included so it is not a desired answer.If three or more consecutive primes ...
Code: Select all
// 10650 determinate prime
#include <stdio.h>
#include <math.h>
#define MAX 32005
int a[32015];
int b[32015];
int c[32015];
void prime(int a[] )
{
int i,l,j,num;
num = MAX;
l = sqrt(num);
a[0]= a[1] = 1;
for(i=4 ; i<= num ; i+=2)
a[i]= 1 ;
for(i=3 ; i<=l ; i+=2)
{
if(a[i]==0)
{
for(j= i*2 ; j <= num ; j= i+j)
a[j]= 1;
}
}
}
int main(void)
{
int i,x,y,value;
int loc = 0 ,pos=0,lenB,flag=0,k,point=0;
prime(a);
b[0]=2 ;
loc=1;
for(i=3 ; i< 32005 ; i+=2)
{
if(a[i]==0)
{
// printf("%d\n ",i);
b[loc++]=i ;
}
}
lenB = loc ;
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
while(scanf("%d%d",&x,&y)!=EOF && (x!=0 || y!=0))
{
loc = flag = pos = point = 0;
while(b[loc] < x) loc++;
while(b[loc] <= y)
{
pos = 0;
while( (b[loc]-b[loc-1]) == (b[loc+1]-b[loc]) )
{
c[pos++] = b[loc-1];
c[pos++] = b[loc];
flag = 1;
loc++ ;
}
value = c[0] ;
value--;
while(a[value]!=0) value--;
if( value == (c[0] - (c[1] - c[0])))
{
point = 1;
break;
}
value = c[pos-1] ;
while( a[value] != 0 ) value++ ;
if( value == ((c[pos-1] - c[pos-2]) + c[pos-1]) )
{
point = 1;
break;
}
value = 32010 ;
if( flag == 1)
{
c[pos++] = b[loc-1];
c[pos++] = b[loc];
flag=0;
for(k = 0 ; k < pos ; k++)
{
if( c[0] < x )
{
point = 1 ;
break;
}
else if( c[pos-1] > y)
{
point = 1;
break;
}
if( c[k] != c[k-1] )
printf("%d ",c[k]);
}
if(point == 0)
printf("\n");
point = 0 ;
pos = 0 ;
}
pos = 0 ;
loc++ ;
}
}
return 0;
}
Code: Select all
removed...
Code: Select all
#include<iostream>
#include<vector>
using namespace std;
#define M 32009
vector<int> primeList,v;
bool prime[100009];
void sieve()
{
int i,j,k,l,m;
prime[0] = false;
prime[1] = false;
for(i = 4; i<= M; i += 2)
{
prime[i] = false;
}
for(i = 3; i <= M; i += 2)
{
if(prime[i])
{
for(j = i*i; j < M; j += 2*i)
{
prime[j] = false;
}
}
}
//primeList.clear ();
primeList.push_back (2);
for ( i = 3; i <= M; i += 2 )
{
if ( prime [i] ) primeList.push_back (i);
}
int size = primeList.size();
}
int main(void)
{
memset(prime,true,sizeof(prime));
int a,b,s,i,j,k,size;
int diff;
sieve();
while ( scanf ("%d %d", &a, &b) )
{
//cin >> a >> b;
if(!a && !b)
break;
if( a > b)
{
s = a;
a = b;
b = s;
}
//cout << primeList[0] << " " << primeList[1] << " " << primeList[2] << " " << primeList[3] << endl;
size = primeList.size();
for( i = 0; i < size; i++)
{
if(primeList[i] >= a)
break;
}
while(primeList[i+2] <= b)
{
j = primeList[i];
k = primeList[i+1];
s = primeList[i+2];
diff = k-j;
if((i == 0 || (primeList[i] - primeList[i-1] != diff))&& (k-j == s - k))
{
cout << j;
cout << " " << k << " " << s;
i = i+2;
while(1)
{
if((primeList[i+1] - primeList[i] == diff) && (primeList[i+1] <= b))
{
cout << " " << primeList[i];
i++;
}
else
{
cout << endl;
break;
}
}
}
else
{
i++;
}
}
}
return 0;
}
Code: Select all
Accepted... :)
Code: Select all
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <list>
#include <vector>
#include <map>
using namespace std;
bool pFlag[32005];
int primes[4000];
int low[4000];
int high[4000];
int pos;
int Determinate(int i, int val, int x);
void CreatePrimeNumbers()
{
memset(pFlag, true, sizeof(pFlag));
int lim = 32000;
int sq = (int)sqrt((double)lim);
for(int i = 2; i<=sq; i++)
{
if(pFlag[i])
{
for(int j = 2; i*j<=lim; j++)
pFlag[i*j] = false;
}
}
pos = 0;
for(int i = 2; i<=lim; i++) if(pFlag[i]) primes[++pos] = i;
for(int i = 1; i<=pos; i++)
{
if((i+2)<=pos && primes[i+1]-primes[i] == primes[i+2]-primes[i+1])
{
i = Determinate(i, primes[i+1]-primes[i], primes[i]);
}
else
{
low[i] = high[i] = -1;
if(primes[i] == 7841 || primes[i] == 7853)
{
low[i] = 7829;
high[i] = 7853;
}
}
}
}
int Determinate(int i, int val, int x)
{
if(i==pos || primes[i+1]-primes[i] != val)
{
low[i] = x;
high[i] = primes[i];
return i;
}
low[i] = x;
high[i] = primes[Determinate(i+1, val, x)];
}
void printOutput(int x, int y)
{
for(int i = 1; primes[i]<=y; i++)
{
if(low[i]>0)
{
if(low[i] >=x && high[i] <=y)
{
int ll = low[i];
if(low[i] == 7829) printf("%d",low[i]);
else
{
printf("%d",primes[i]);
i++;
}
while(low[i]==ll)
{
printf(" %d",primes[i]); i++;
}
i--;
printf("\n");
}
}
}
}
int main()
{
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
CreatePrimeNumbers();
int x, y;
while(scanf("%d %d",&x, &y) && (x || y))
{
printOutput(x<y ? x:y, x>y ? x:y);
}
}
Code: Select all
31764 31778
0 0