Tìm số nguyên tố
View as PDF
Submit solution
Points:
0.01 (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
Dùng sàng số nguyên tố ý, bị mỗi cái a,b<=200000 nên có k/n TLE
à sorry, thiếu mấy cái input với nhầm 200000 thành 1e6 nhed, sorry mn
include <bits/stdc++.h>
using namespace std; bool isPrime(int n){ if (n<2) return false; else{ for (int i=2;i*i<=n;i++){ if (n%i==0) return false; } return true; } } int main(){ iosbase::syncwith_stdio(0); cin.tie(0); cout.tie(0); int a,b; cin>>a>>b; for (int i=a;i<=b;i++){ if (isPrime(i)) cout<<i<<endl; } }
đang luyện code miller-rabin
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.
Java template (Delegate Quick Scanner) for faster IO (e.g. constraint 0.3s instead of 1s)
(the template is re-usable for other problems)
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.
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.