2 solutions
-
0
模拟(60pts)
- 枚举2到的数,如果是的因子,那么就更新答案,最后从小到大去枚举,最后一次遇到的就是最大的质数。
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int res=0; for(int i=2;i<n;i++) //从2到n枚举因子 { if(n%i==0) { res=i; //更新答案 } } cout<<res; return 0; }
模拟优化(100pts)
- 我们知道因子一定是成对出现的,那么最后出现的一个前一定在前面就已经出现过更小的,且我们可以通过的小的因子算出大的因子。
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; for(int i=2;i<=n/i;i++) //枚举小因子 { if(n%i==0) //找到小因子 { cout<<n/i; //找到大因子 return 0; } } return 0; }
- 1
Information
- ID
- 437
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 5
- Accepted
- 4
- Uploaded By