3 条题解

  • 2
    @ 2023-12-14 18:56:13

    如果n能被某个合数整除,那么同样会被这个合数的质因数整除,而这些质因数都比合数小,所以第一个遇到的因数一定是质数。

    扩展一下,在递增过程中,如果我们每遇到一个质数,就把这个质数的倍数剔除,那么一路上你遇到的都会是质数。(埃氏质数筛原理)

    • 2
      @ 2023-12-14 18:44:28

      题目已经明确了n是两个质数的积,那么从2一直试上去,找到第一个因数a是最小的,那么n/a就是大的那个。

      (思考:为什么找到的第一个因数一定是质数?)

      #include <bits/stdc++.h>
      using namespace std;
      
      int main(){
          int n,i=2;
          cin>>n;
          for (i=2;i<=n/i;i++) if (n%i==0) break;
          cout<<n/i;
          return 0;
      }
      
      • 2
        @ 2023-10-3 11:30:24
        #include<iostream>
        #include<cstring>
        #include<string>
        #include<cstdio>
        #include<cmath>
        #include<algorithm>
        using namespace std;
        int main(){
        	int n;
        	cin >> n;
        	for(int i=2;i*i<=n;i++){
        		if(n%i == 0){
        			cout << max(n/i,i);
        			break;
        		}
        	}
        	return 0;
        }
        
        • 1

        信息

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