Thứ Ba, 3 tháng 5, 2022

DIVISORS C++

#include<bits/stdc++.h>
using namespace std;

int n;

bool ngto(int x)
{
    for(int i=2;i<=int(sqrt(x));i++)
    {
        if(x%i==0) return false;
    }
    return true;
}
void giai()
{
    int a,j,d=1;
    for(int i=2;i<=n;i++)
    {
        if(ngto(i)==true)
        {
            a=0;j=i;
            while(n/j>0)
            {
                a=a+n/j;
                j=j*i;
            }
            //cout<<i<<" "<<a<<endl;
            d=d*(a+1);
        }
    }
    cout<<(d-1);
}
void nhap()
{
    cin>>n;
}
int main()
{
    freopen("divisors.inp","r",stdin);
    freopen("divisors.out","w",stdout);
    nhap();
    giai();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.