文章

49

粉丝

140

获赞

27

访问

15.6k

头像
约数的个数 题解:认真分析,最好用sqrt,还要考虑例如6*6这种情况
P1152 清华大学上机题
发布于2024年3月9日 17:38
阅读数 145

#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int main(){


	int n,count=0;
	int a[1005];
	while(scanf("%d",&n)!=EOF){
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			cin >> a[i];
		for(int j=0;j<n;j++){
			count =0;
		for(int i=1;i<=sqrt(a[j]*1.0);i++)
		{     if(a[j]%i==0){
		 if(a[j]/i==i)
		   count++;
		else
			count=count+2;}
		}
		//if(a[j]==1)
		cout << count <<endl;
		//else if(sqrt(a[j]*1.0)*sqrt(a[j]*1.0)==a[j])
			  //cout << count*2-1<<endl;
		//else
      // cout << count*2 <<endl;
		}
	}
	//system("pause");
	return 0;

}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发