UVa 10699 - Count the factors Solution

#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
bitset<1001> p;
vector<int> prime;
void calc(){
    int tmp=1000;
    int tmp2=32;
    for(int i=2;i<=tmp;i++){
        if(!p[i]){
            prime.push_back(i);
            if(i<=tmp2)
                for(int j=i*i;j<=tmp;j+=i)
                    p[j]=1;
        }
    }
}
int main(){
    calc();
    ios::sync_with_stdio(0);
    int n,N;
    while(cin>>n&&n){
        N=n;
        int ans=0;
        for(int i=0;i<prime.size()&&prime[i]<=n;i++){
            if(n%prime[i]==0)
                ans++;
            while(n%prime[i]==0){
                n/=prime[i];
            }
        }
        if(n>1)
            ans++;
        cout<<N<<" : "<<ans<<endl;
    }
}

Comments