CSES Solutions
#1713Mathematics

Counting Divisors

View on CSES

Solution

1713-Counting_Divisors.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4int p[1000001];
5signed main(){
6  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
7  for(int i=2;i<1000001;++i) if(!p[i]) for(int j=i;j<1000001;j+=i)
8    p[j]=i;
9  int n; cin>>n;
10  for(;n;--n){
11    int x,ans=1; cin>>x;
12    for(int i=0,res=1,k=p[x];k;++i,ans*=res,res=1,k=p[x]) while(x%k==0)
13      x/=k,++res;
14    cout<<ans<<'\n';
15  }
16  return 0;
17}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.