C++ 寻找亲密数对算法实现 日期: 2028-11-10 标签: 常规 #include #include #include #include #include using namespace std; const int maxn=2005; int f[maxn],n; void init() { for(int i=2;i<=sqrt(maxn);i++) { for(int j=i*i;j<maxn;j+=i) { f[j]+=i; if(j/i!=i) f[j]+=j/i; } } } int main() { init(); cin>>n; for(int i=2;i<=n;i++) { if(f[i]>i&&f[f[i]]==i) cout<<i<<' '<<f[i]<<endl; } return 0; } 原文地址: https://www.cveoy.top/t/topic/owb8 著作权归作者所有。请勿转载和采集! 免费AI点我,无需注册和登录