Tìm số nguyên tố

View as PDF

Submit solution


Points: 0.03 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Problem source:
Dân gian
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

Please read the guidelines before commenting.



  • -9
    kietjumper  commented on Aug. 25, 2024, 5:00 p.m. edit 3

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -6
      kietjumper  commented on Aug. 25, 2024, 5:03 p.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


  • -7
    Trau_4  commented on July 26, 2024, 8:49 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    hohoanghai5042011  commented on July 12, 2024, 2:11 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -2
      kietjumper  commented on Aug. 25, 2024, 5:15 p.m.

      Lan sau Spoil nhe!


  • -5
    zatarainbow  commented on July 7, 2024, 6:53 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • 0
    ChiPhatNguyen  commented on June 23, 2024, 4:08 a.m.

    Links https://youtu.be/U8eNPUUpN6A?si=V6Fg7O1nDCVdU1de* video về sàng cho ae nào chưa bt*


  • -2
    ChiPhatNguyen  commented on June 23, 2024, 4:04 a.m. edit 7

    include <bits/stdc++.h>

    using namespace std;

    bool snt(int n){

    if(n < 2) return false;
    
    for(int i = 2;i<=sqrt(n);i++){
    
        if(n%i==0) return false;
    
    }
    
    return true;
    

    } int prime[100000];

    void sang(){

    for(int i = 1;i<=1000000;i++){
    
        prime[i] = 1;
    
    }
    
    prime[0] = prime[1] = 0;
    
    for(int i = 2;i<=sqrt(10000000);i++){
    
        if(prime[i]==1){
    
            for(int j = i*i;j<=1000000;j+=i)
    
            prime[j] = 0;
    
        }
    
    }
    

    } int main(){

    int a,b;
    
    cin>>a>>b;
    
    sang();
    
    for(int i = a;i<=b;i++){
    
        if (prime[i]==1)
    
        cout << i << " " << endl; /// sai = + 1 loli
    
    }
    
    return 0;
    

    }

    https://youtu.be/U8eNPUUpN6A?si=V6Fg7O1nDCVdU1de

    sao lại ko AC full v nhnhỉ


  • -1
    winky  commented on April 27, 2024, 7:11 p.m.

    bài này dùng miller rabin nha


    • 2
      lemonpro134  commented on May 3, 2024, 1:03 p.m.

      dùng sàng thôi cx đủ rồi


  • -16
    ElmiraAthena  commented on Feb. 1, 2024, 1:14 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -1
      kietjumper  commented on Aug. 25, 2024, 5:15 p.m.

      Cai Gi Vay Ban???


  • 6
    thanhhoang  commented on Jan. 23, 2024, 6:50 p.m.

    Dùng sàng nguyên tố.


  • 1
    khoitran  commented on Jan. 13, 2024, 8:39 a.m.

    Bài này cứ dùng sàng là ok


  • -82
    nthquan_1505  commented on March 30, 2023, 4:22 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -79
    nthquan_1505  commented on March 30, 2023, 4:22 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.