cf1203C C. Common Divisors
作者:互联网
问题分析
gcd + 优化 (一个数的因数至少有一半小于等于 sqrt(这个因数)
AC代码如下:
#include<iostream>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
const int maxn=4e5+3;
long long num[maxn] ;
set<long long > number;
long long gcd(long long a,long long b){
while(b){
long long t=b;
b=a%b;
a=t;
}
return a;
}
int main(){
int n;
scanf("%lld,%lld",&n,&num[0]);
long long gc=num[0];
for(int i=1;i<n;i++){
scanf("%lld",&num[i]);
gc=gcd(gc,num[i]);
}
long long sum;
for(int i=1;i*i<=gc;i++){
if(gc%i==0)
sum++;
if(i*i!=gc)
sum++;
}
cout<<sum<<endl;
return 0;
}
标签:cf1203C,gcd,int,long,num,Common,include,Divisors,lld 来源: https://www.cnblogs.com/maxv/p/11767774.html