/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
int data[1000005] ;
int prime[80000] ;
int cnt ;
void isPrime()
{
int i,j ;
memset(data,0,sizeof(data)) ;
cnt =0 ;
for(i=2 ; i<1000005 ; i++)
{
if(!data[i])
{
prime[cnt++] =i ;
for(j= i+i ; j<1000005 ; j+=i)
data[j] =1 ;
}
}
}
int main()
{
//pf("Hello\n") ;
isPrime() ;
int save[5000] ;
int test,mx,i,cont ;
sc("%d",&test) ;
while(test--)
{
int U , L ;
sc("%d %d",&L,&U) ;
memset(save,0,sizeof(save)) ;
for(i=0 ; i<cnt ; i++)
{
if(prime[i+1]>U)
break ;
if(prime[i]>=L && prime[i+1]<=U)
{
save[prime[i+1]-prime[i]]++ ;
}
}
mx =0 ;
for(i=1 ; i<120 ; i++)
{
if(save[mx]<save[i])
mx =i ;
}
cont =0 ;
for(i=1 ; i<120 ; i++)
{
if(save[mx]==save[i])
cont++ ;
}
if(mx<1 || cont>1)
pf("No jumping champion\n") ;
else
pf("The jumping champion is %d\n",mx) ;
}
return 0;
}
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
int data[1000005] ;
int prime[80000] ;
int cnt ;
void isPrime()
{
int i,j ;
memset(data,0,sizeof(data)) ;
cnt =0 ;
for(i=2 ; i<1000005 ; i++)
{
if(!data[i])
{
prime[cnt++] =i ;
for(j= i+i ; j<1000005 ; j+=i)
data[j] =1 ;
}
}
}
int main()
{
//pf("Hello\n") ;
isPrime() ;
int save[5000] ;
int test,mx,i,cont ;
sc("%d",&test) ;
while(test--)
{
int U , L ;
sc("%d %d",&L,&U) ;
memset(save,0,sizeof(save)) ;
for(i=0 ; i<cnt ; i++)
{
if(prime[i+1]>U)
break ;
if(prime[i]>=L && prime[i+1]<=U)
{
save[prime[i+1]-prime[i]]++ ;
}
}
mx =0 ;
for(i=1 ; i<120 ; i++)
{
if(save[mx]<save[i])
mx =i ;
}
cont =0 ;
for(i=1 ; i<120 ; i++)
{
if(save[mx]==save[i])
cont++ ;
}
if(mx<1 || cont>1)
pf("No jumping champion\n") ;
else
pf("The jumping champion is %d\n",mx) ;
}
return 0;
}
No comments:
Post a Comment