56-题目1087:约数的个数

来源:互联网 发布:intent传递int数据 编辑:程序博客网 时间:2024/05/19 22:02

http://ac.jobdu.com/problem.php?pid=1087

题目描述:

输入n个整数,依次输出每个数的约数的个数

#include<iostream>#include<fstream>#include<math.h>using namespace std;int main(){int n, num;ifstream cin("data.txt");while (cin >> n && n != 0){for (; n > 0; n--){cin >> num;int count = 0, j;for (j = 1; j < sqrt(num) + 1 && j <= num / j; j++){if (num == 1)count++;else if (num % j == 0){if (j == num / j)count++;elsecount += 2;}}cout << count << endl;}}system("pause");return 0;}


0 0