Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- // #pragma GCC optimize("Ofast,no-stack-protector")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- // #pragma GCC optimize("unroll-loops")
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double lld;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef vector<vi> vvi;
- typedef pair<int,int > pii;
- typedef pair<ll,ll > pll;
- typedef vector< pii > vpii;
- typedef vector< pll > vpll;
- typedef set<int> sti;
- #define sc scanf
- #define pf printf
- #define sci(n) scanf("%d",&n)
- #define scii(n,m) scanf("%d %d",&n,&m)
- #define scl(n) scanf("%lld",&n)
- #define scd(n) scanf("%lf",&n)
- #define scs(s) scanf("%s",s)
- #define pfi(n) printf("%d",n)
- #define pfl(n) printf("%lld",n)
- #define pff(n) cout<<n
- #define spc printf(" ")
- #define line printf("\n")
- #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
- #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
- #define cspf(i) printf("Case %d: ", i)
- #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
- #define clr(a,x) memset(a,x,sizeof(a))
- #define tp(v,j) get<j>(v)
- #define pb push_back
- #define mp make_pair
- #define mt make_tuple
- #define ff first
- #define ss second
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
- /// Constants
- #define eps 1e-6
- #define PI acos(-1.0) // 3.1415926535897932
- #define MAX 1e9
- #define MAXn 1000009
- int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
- ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
- vi prime;
- bitset<MAXn>chk;
- int cnt[80000][120];
- void seive()
- {
- chk[0]=chk[1]=1;
- for(int i=4;i<MAXn;i+=2) chk[i]=1;
- for(int i=3;i<=MAXn/i;i+=2){
- if(chk[i]) continue;
- for(int j=i*i;j<MAXn;j+=(2*i)) chk[j]=1;
- }
- prime.pb(2);
- for(int i=3;i<MAXn;i+=2){
- if(!chk[i]) prime.pb(i);
- }
- clr(cnt,0);
- for(int i=1;i<prime.size();i++){
- int x = prime[i]-prime[i-1];
- for(int j=1;j<115;j++){
- if(x==j) cnt[i][j]=cnt[i-1][j]+1;
- else cnt[i][j]=cnt[i-1][j];
- }
- }
- }
- int BSup(int lo,int hi,int n)
- {
- if(lo>hi) return MAX;
- int mid = (lo+hi)/2;
- if(prime[mid]>=n) return min(mid, BSup(lo,mid-1,n));
- return BSup(mid+1,hi,n);
- }
- int BSlo(int lo,int hi,int c)
- {
- if(lo>hi) return -1;
- int mid = (lo+hi)/2;
- if(prime[mid]<=c) return max(mid, BSlo(mid+1,hi,c));
- return BSlo(lo,mid-1,c);
- }
- int main()
- {
- #ifdef VAMP
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- seive();
- int t;
- sci(t);
- while(t--){
- int l,u;
- scii(l,u);
- if(u<=2){
- pf("No jumping champion\n");
- continue;
- }
- int st = BSup(0,prime.size()-1,l);
- int en = BSlo(0,prime.size()-1,u);
- if(st>=en){
- pf("No jumping champion\n");
- continue;
- }
- bool f=true;
- int mx=0,index=0,x;
- for(int i=1;i<115;i++){
- x = cnt[en][i]-cnt[st][i];
- if(x>mx) mx=x;
- }
- if(!mx){
- pf("No jumping champion\n");
- continue;
- }
- for(int i=1;i<115;i++){
- x = cnt[en][i]-cnt[st][i];
- if(x==mx){
- if(!index) index=i;
- else{
- f=false;
- break;
- }
- }
- }
- if(f) pf("The jumping champion is %d\n",index);
- else pf("No jumping champion\n");
- }
- #ifdef VAMP
- fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement