1 条题解

  • 0
    @ 2021-6-15 9:42:27

    C :

    #include<stdio.h>
    int main()
    {
      int num;
      while (scanf("%d",&num)!=EOF)
      {
    	  int i;
    	  for (i=2;i*i<=num;i++)
    	  {
    		  if (num%i==0) 
    		  {
    			  printf("%d\n",num/i);
    			  break;
    		  }	 
    	  }
      }
      return 0;
    }
    

    C++ :

    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int m=sqrt(n);
        int i,k;
        for(i=2;i<=m;i++)
            if(n%i==0) {k=i;break;}
        cout<<n/k;
        return 0;
    }
    

    Pascal :

    uses math; 
    var n,i:longint; 
    function prime(x:longint):boolean; 
    var i:longint; 
    begin
      for i:=2 to trunc(sqrt(x)) do if x mod i=0 then exit(false); 
      exit(true); 
    end; 
    begin
      read(n); 
      i:=2; 
      repeat
        if (n mod i=0) and prime(i) and prime(n div i) then
          begin
            writeln(max(i,n div i)); 
            halt; 
          end; 
        i:=i+1; 
      until i>(trunc(sqrt(n))); 
    end.
    

    Java :

    import java.util.*;
    public class Main{
      public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        long startTime = System.currentTimeMillis();
        int n = cin.nextInt();
        for(int i = 2; i <= n/2; i ++){
          if(n%i==0){
            System.out.println(n/i);
            break;
          }
        }
        long endTime = System.currentTimeMillis();
        long totalTime = endTime - startTime;
        // System.out.println("\n"+totalTime);
      }
    
      public static int isPrime(int n){
        if(n == 1 || n ==0){
          return 0;
        }
        for(int i = 2; i <= (int)Math.sqrt(n); i ++){
          if(n%i==0){
            return 0;
          }
        }
        return 1;
      }
    }
    
    

    Python :

    # coding=utf-8
    def main():
        n = int(input())
    
        v = 0 
        for i in range(2, n):
            if n % i == 0:
                v = max(i, n/i)
                break
        
        print(int(v))
    
    if __name__ == '__main__':
        main()
    
    • 1

    信息

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