1 solutions

  • 0
    @ 2025-11-5 16:32:55

    C++ :

    #include<cstdio>
    #include<cstring>
    	bool bz[1000010];
    	int n,t=0;
    int main()
    {
    	scanf("%d",&n);
    	memset(bz,true,sizeof(bz));
    	for(int i=2;i<=n;i++)
    		if(bz[i])
    			for(int j=2;j<=n/i;j++)
    				bz[i*j]=false;
    	bz[1]=false;
    	for(int i=1;i<=n;i++)
    		if(bz[i]) t++;
    	printf("%d",t);
    }
    

    Pascal :

    var n,s,j,i:longint;
        b:boolean;
    begin
      readln(n);
      s:=0;
      for i:=1 to n do
      begin
        b:=true;
        for j:=2 to trunc(sqrt(i)) do
          if i mod j=0 then b:=false;
        if b then inc(s);
      end;
      writeln(s-1);
    end.
    
    • 1

    Information

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