本文主要是介绍HDU1215和相亲数、完全数、循环数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
七夕节
*Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 64736 Accepted Submission(s): 21136
*
Problem Description
七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:“你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!”
人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:
数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6.
你想知道你的另一半吗?
Input
输入数据的第一行是一个数字T(1<=T<=500000),它表明测试数据的组数.然后是T组测试数据,每组测试数据只有一个数字N(1<=N<=500000).
Output
对于每组测试数据,请输出一个代表输入数据N的另一半的编号.
Sample Input
3
2
10
20
Sample Output
1
8
22
Author
Ignatius.L
Source
杭电ACM省赛集训队选拔赛之热身赛
Recommend
Eddy | We have carefully selected several similar problems for you: 1406 1211 1214 1201 1212
代码
#include <bits/stdc++.h>
using namespace std;long long dia[1000010];int main()
{int t;cin>> t;while(t --){int n;scanf("%d", &n);long long sum = 1;for(int i = 2; i * i <= n; i ++){if(n % i == 0){sum += i;if(i * i != n) sum += n / i;}}printf("%lld\n",sum);}return 0;
}
转点别的
完全数
#include <bits/stdc++.h>
using namespace std;long long dia[1000010];int main()
{int t;cin>> t;while(t --){int n;scanf("%d", &n);long long sum = 1;for(int i = 2; i * i <= n; i ++){if(n % i == 0){sum += i;if(i * i != n) sum += n / i;}}sum -= n;if(sum == 0){puts("完全数");}else if(sum > 0){puts("盈数");}else{puts("亏数");}}return 0;
}
相亲数
#include <bits/stdc++.h>
using namespace std;long long dia[1000010];int main()
{int t;cin>> t;while(t --){int a, b;scanf("%d%d", &a,&b);if(a == b){puts("普通数");continue;}long long sum1 = 1;long long sum =1;int n = a ;for(int i = 2; i * i <= n; i ++){if(n % i == 0){sum += i;if(i * i != n) sum += n / i;}}n = b;for(int i = 2; i * i <= n; i ++){if(n % i == 0){sum1 += i;if(i * i != n) sum1 += n / i;}}if(sum == b && sum1 == a){puts("相亲数");}else{puts("普通数");}}return 0;
}
循环
#include <bits/stdc++.h>
using namespace std;long long dia[1000010];int main()
{int t;cin>> t;while(t --){int a, b;scanf("%d%d", &a,&b);if(a == b){puts("普通数");continue;}long long sum1 = 1;long long sum =1;int n = a ;for(int i = 2; i * i <= n; i ++){if(n % i == 0){sum += i;if(i * i != n) sum += n / i;}}n = b;for(int i = 2; i * i <= n; i ++){if(n % i == 0){sum1 += i;if(i * i != n) sum1 += n / i;}}if(sum == b && sum1 == a){puts("相亲数");}else{puts("普通数");}}return 0;
}
循环数
#include <bits/stdc++.h>
using namespace std;long long dia[1000010];int main()
{int n;cin >> n;for(int q=1; q <= 100; q ++){printf("%d: ", q);int t = n;while(t--){long long sum = 1;for(int i = 2; i * i <= q; i ++){if(q % i == 0){sum += i;if(i * i != q) sum += q / i;}}printf("%d ", sum);}printf("\n");}return 0;
}
这篇关于HDU1215和相亲数、完全数、循环数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!