Thứ Bảy, 4 tháng 12, 2021

phantich c++


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

int n,d,k,x[1000000],a[1000000],dem,s=0;
bool ok;
void nhap()
{
    cin>>n>>k;
}
void tim_uoc()
{
    d=1;a[d]=k;
    for(int i=2;i<=int(sqrt(k));i++)
    {
        if(k%i==0)
        {
            d++;a[d]=i;
            d++;a[d]=k/i;
        }
    }
    if(sqrt(k)==int(sqrt(k))) d--;
}
void xuat(int p)
{
    if(ok==true) return;
    for(int i=1;i<=p;i++)
    {
        if(x[i]>0)
            cout<<a[i]<<" "<<x[i]<<endl;
    }
}
void vet(int i)
{
    if(ok==true) return;
    for(int j=0;j<=(n-s)/a[i];j++)
    {
        x[i]=j;
        s=s+j*a[i];
        if(i==d||s>=n)
        {
            if(s==n)
            {
                xuat(i);
                ok=true;
            }
        }
        else vet(i+1);
        s=s-j*a[i];
    }
}
int main()
{
    freopen("phantich.inp","r",stdin);
    freopen("phantich.out","w",stdout);
    nhap();
    tim_uoc();
    ok=false;
    vet(1);
    if(ok==false) cout<<0;
}

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.