求数n之内的亲密对数。所谓“亲密对数”,即A的所有因子(包含1但不包含其本身)之和等于B,而B的所有因子之和等于A。我的程序:#include<iostream>using namespace std;int main(){int spouse(int);int v,n,i,add;cin>>n;for(i=2;i<n;i++) { add=spouse(i); v=spouse(add); if(add==v&&add!=v) cout<<i<<" "<<add;}return 0;} int spouse(int add){ int t,sum=0; for(t=1;t<=add;t++) { if(add%t==0) sum=sum+t;} return sum; }
3 回答
已采纳
xungeer29
TA贡献46条经验 获得超20个赞
#include<iostream>
using namespace std;
int spouse(int);
int main()
{
int v, n, i, add;
cin >> n;
for (i = 2; i<n; i++)
{
add = spouse(i);
v = spouse(add);
if (i==v&&i!=add)
cout << i << " " << add << endl;
}
return 0;
}
int spouse(int add)
{
int t, sum = 0;
for (t = 1; t < add; t++)
{
if (add%t == 0)
sum = sum + t;
}
return sum;
}
using namespace std;
int spouse(int);
int main()
{
int v, n, i, add;
cin >> n;
for (i = 2; i<n; i++)
{
add = spouse(i);
v = spouse(add);
if (i==v&&i!=add)
cout << i << " " << add << endl;
}
return 0;
}
int spouse(int add)
{
int t, sum = 0;
for (t = 1; t < add; t++)
{
if (add%t == 0)
sum = sum + t;
}
return sum;
}
- 3 回答
- 0 关注
- 1890 浏览
添加回答
举报
0/150
提交
取消