Toph Number theory Problem Largest Prime Solution

Solve in C++:
///**********ALLAH IS ALMIGHTY************/// ///AH Tonmoy ///Department of CSE ///Islamic University,Bangladesh #include<bits/stdc++.h> #define M 100100 using namespace std; bool marked[M]; void sieve() { for(int i=4; i<=M; i+=2) marked[i]=true; marked[1]=true; for(int i=3; i*i<=M; i+=2) { if(marked[i]==false) { for(int j=i*i; j<=M; j+=i) { marked[j]=true; } } } } main() { long long n,i,s=0,l,r,mx=0; long long t; cin>>t; sieve(); while(t--) { mx=0,s=0; cin>>l>>r; for(i=r; i>=l; i--) { if(marked[i]==false) { s=1; mx=i; break; } } if(l==1&&r==1) cout<<"-1"<<endl; else { if(s==1) cout<<mx<<endl; else cout<<"-1"<<endl; } } }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.