Untitled
raw download clone
TEXT
views 19
,
size 933 b
#include <iostream>
using namespace std;
void citire (int &n, int v[])
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>v[i];
}
void afisare(int n, int v[])
{
    for(int i=0;i<n;i++)
        cout<<v[i]<<" ";
}
int redus(int n)
{
	int d=2, r=1;
    while(n>1)
    {
        if(n%d == 0)
        {
            r*=d;
            while(n%d == 0)
                n/=d;
        }
        d++;
        if(d*d > n)
            d=n;
    }
    return r;
}
void sortare(int n,int v[])
{
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
            if(v[i]<v[j])
            {
                int aux=v[i];
                v[i]=v[j];
                v[j]=aux;
            }
}
void inloc(int n, int v[])
{
    for(int i=0;i<n;i++)
        v[i]=redus(v[i]);
}
int main()
{
    int n,v[1001];
    citire(n,v);
    inloc(n,v);
    sortare(n,v);
    afisare(n,v);
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.