1 条题解

  • 0
    @ 2025-2-14 20:52:08

    C :

    #include<stdio.h>
    void fun(int n)
    {
    	int i;
    	for(i=2;i<n-1;i++) 
    		if(n%i==0) 
    		{  
    			printf("Not Prime!\n",n); 
    			break;  
    		} 
    		if(i==n-1) 
    			printf("Prime!\n",n);
    }
    void main()
    { 
    	int n,i;
    	scanf("%d",&n); 
    	fun(n);
    }
    

    C++ :

    #include<stdio.h>
    int main()
    {int sushu(int);
     int l;
     scanf("%d",&l);
     if(l>=1)
     {if(sushu(l))
       printf("Prime!\n");
       else
       printf("Not Prime!\n");
     }
     else
       printf("Error!\n");
     return 0;
    }
    
    int sushu(int l)
    {
      int world=1,z;
      for(z=2;z<l/2&&world==1;z++)
        if(l%z==0)
        world=0;
        return(world);
    }
     
    

    Pascal :

    program acm26338;
    var n:longint;
    function ss(n:longint):string;
    var i,c:longint;
    begin
     c:=0;
     for i:=1 to trunc(sqr(n)) do
      if n mod i=0 then c:=c+1;
     if c=2
      then ss:='Prime!'
      else ss:='Not Prime!';
    end;
    begin
     read(n);
     writeln(ss(n));
    end.
    
    • 1

    信息

    ID
    491
    时间
    1000ms
    内存
    12MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者