Submit solution
Points:
0.03 (partial)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Problem source:
Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch
Hãy tìm tất cả các số nguyên tố trong đoạn ~[A~, ~B]~.
Input
Gồm ~2~ số nguyên ~A~ và ~B~ cách nhau bởi ~1~ dấu cách ~(1 \leq A \leq B \leq 200000)~.
Output
Ghi ra tất cả các số nguyên tố trong đoạn ~[A~, ~B]~ theo thứ tự tăng dần. Mỗi số trên ~1~ dòng.
Sample Input
1 10
Sample Output
2
3
5
7
Comments
include<bits/stdc++.h>
using namespace std; bool snt(long long n){ if(n==2||n==3) return true; if(n<2||n%2==0||n%3==0) return false ; long long k=-1,cbh=trunc(sqrt(n)); while(k<=cbh){ k+=6; if(n%k==0||n%(k+2)==0) break; } return (k>cbh); } int n; int main() { long long A,B; cin>>A>>B; for(int i=A;i<=B;i++) if(snt(i)) cout<<i<<endl return> </endl>
include<iostream>
include<vector>
using namespace std; typedef long long ll; ll l,k; void sang(ll l,ll k){ vector<bool> A(k+1,true); A[0]=A[1]=false; for(ll i=2;ii<=k;i++){ if(A[i]) { for(ll j=ii;j<=k;j+=i) A[j]=false; } } for(ll i=l;i<=k;i++) { if(A[i]) cout<<i<<"\n"; } } int main(){ cin>>l>>k; sang(l,k); }
Java template (Delegate Quick Scanner) for faster IO (e.g. constraint 0.3s instead of 1s)
(the template is re-usable for other problems)
include<bits/stdc++.h>
using namespace std; bool kt(long long b) { if(b<2) return false; for (int i=2;i<=sqrt(b);i++) { if(b%i==0) { return false; } } return true; } int main() { long long a,b; cin>>a>>b; for(int i=a;i<=b;i++) { if(kt(i)) { cout<<i<<endl return> </endl>
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
Links https://youtu.be/U8eNPUUpN6A?si=V6Fg7O1nDCVdU1de* video về sàng cho ae nào chưa bt*
include <bits/stdc++.h>
using namespace std;
bool snt(int n){
} int prime[100000];
void sang(){
} int main(){
}
https://youtu.be/U8eNPUUpN6A?si=V6Fg7O1nDCVdU1de
sao lại ko AC full v nhnhỉ
bài này dùng miller rabin nha
dùng sàng thôi cx đủ rồi
This comment is hidden due to too much negative feedback. Show it anyway.
Dùng sàng nguyên tố.
Bài này cứ dùng sàng là ok
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.