1 条题解

  • 0
    @ 2023-6-11 12:15:50

    C :

    #include<stdio.h>
    
    int fun(int n){
    	int r=1,i;
    	for(i=2;i*i<=n;i++){
    		if(n%i==0){
    			r=0;
    			break;
    		}
    	}
    	if(n==1){
    		r=0;
    	}
    	return r;
    }
    int tong(int n){
    	int r=0,i;
    	for(i=2;i*i<=n;i++){
    		if(n%i==0&&fun(i)==1&&fun(n/i)==1){
    			r=1;
    			break;
    		}
    	}
    	return r;
    }
    
    void main(){
    	int n;
    	scanf("%d",&n);
    
    	if(tong(n)==1){
    		printf("%s","It's a Tongtong number.");
    	}else{
    		printf("%s","It's not a Tongtong number.");
    		}
    }
    
    

    C++ :

    #include <iostream>
    #include <cmath>
    using namespace std;
    bool sushu(int n){
    	bool r=true;
    	int i;
    	for(i=2;i<=sqrt(n);i++){
    		if(n%i==0){
    			r=false;
    			break;
    		}
    	}
    	if(n<=1){
    		r=false;
    	}
    	return r;
    }
    void chaifeng(int n){
    	int i;
    	for(i=2;i<=n/2;i++){
    		if(n%i==0){
    			if(sushu(i)==true&&sushu(n/i)==true){ 
    			cout<<"It's a Tongtong number."<<endl;	
    			break;
    		}else {
    			cout<<"It's not a Tongtong number."<<endl;
    			break;
    			
    		}
    }
    	}
    }
    int main(){
    	int n;
    	cin>>n;
    	chaifeng(n);
    }
    

    Python :

    import math
    def suShu(n):
        f = True
        for i in range (2, int(math.sqrt(n))+1):
            if n % i == 0:
                f = False; 
        return f and n != 1
        
    n = int(input())
    f = False;
    for a in range(2,int(math.sqrt(n))+1):
            for b in range (int(math.sqrt(n))+1, n ):
                    if n == a * b and suShu(a) and suShu(b):
                        f = True;
    if f:
         print("It's a Tongtong number.")
    else:
         print("It's not a Tongtong number.")
    
    
    
    • 1

    信息

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