6 solutions

  • 1
    @ 2023-8-15 9:18:58

    先用上题的循环判断是不是能被除,这里能被除说明是因数。是因数之后判断是不是质数。如果是质数的话,则输出较大的那个数,也就是j。

    #include<bits/stdc++.h>
    using namespace std;
    bool zhishu(int x){
    	bool flag = true;
    	int i;
    	for(i=2;i<=sqrt(x);i++){
    		if(x % i == 0){
    			flag = false;
    			break;
    		}
    	}
    	return flag;
    }
    int main(){
    	int x, i, j;
    	cin >> x;
    	for(i = 2; i <= sqrt(x); i++){
    		if(x % i == 0 && zhishu(i)){
    			j = x / i;
    			break;
    		}
    	}
    	cout << j << endl;
    }
    

    Information

    ID
    44
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    968
    Accepted
    234
    Uploaded By