1 solutions

  • 0
    @ 2025-11-5 20:08:15

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int n,m,a[100005];
    int main()
    {
        cin>>n>>m;a[1]=1;
        for(int i=2;i*i<=100000;i++)
        {
        	if(a[i]==0)
        	for(int j=i+i;j<=100000;j+=i)
        	a[j]=1;
    	}
    	for(int i=1;i<=100000;i++)
    	{
    		if(a[i]==0)a[i]=a[i-1]+1;
    		else a[i]=a[i-1];
    	}
    	cout<<a[m]-a[n-1];    
    	return 0;
    }
    

    Pascal :

    var k,i,m,n,t:longint;
    pd:boolean;
    begin
    	readln(n,m);
    	for i:=n to m do
          begin
        	pd:=true;
    		for k:=2 to trunc(sqrt(i)) do
              if i mod k = 0 then begin pd:=false;break;end;
    		if i=1 then pd:=false;
    		if pd then inc(t);
    	  end;
    	writeln(t);
    end.
    
    • 1

    Information

    ID
    20047
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By