/*
Se dă un vector cu n elemente, numere naturale. Afișați în ordine descrescătoare valorile din vector care sunt prime cu ultimul element al vectorului.
Input:
Programul citește de la tastatură numărul n, iar apoi n numere naturale, reprezentând elementele vectorului
Output:
Programul va afișa pe ecran valorile cerute, în ordine descrescătoare, separate prin exact un spațiu.
Restrictii si precizari:
- 1 <= n <= 1000
- cele n numere citite vor fi mai mici decât 1.000.000.000
Example:
Input:
8
16 7 63 1 5 9 14
Output:
9 5 3 1
*/
#include <stdio.h>
void countingsort(long long *p, int n) {
long long B[n+1], C[n+1], i, j;
for(i = 0; i < n; ++i) C[i] = p[i];
for(i = 0; i < n; ++i) B[i] = 0;
for(i = 0; i < n - 1; ++i) {
for(j = i + 1; j < n; ++j) {
if(C[i] < C[j]) {
B[i]++;
} else {
B[j]++;
}
}
}
for(i = 0; i < n; ++i) p[B[i]] = C[i];
}
int euclid(int a, int b) {
int r;
while(b) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
int i, j, n, k = 0;
long long arr[n+1], arr2[n+1];
for(i = 0; i < n; ++i){
}
for(i = 0; i < n - 1; ++i) {
if(euclid(arr[i], arr[n-1]) == 1) {
arr2[k++] = arr[i];
}
}
countingsort(arr2, k);
for(i = 0; i < k; ++i) {
}
return(0);
}
LyoKU2UgZMSDIHVuIHZlY3RvciBjdSBuIGVsZW1lbnRlLCBudW1lcmUgbmF0dXJhbGUuIEFmaciZYcibaSDDrm4gb3JkaW5lIGRlc2NyZXNjxIN0b2FyZSB2YWxvcmlsZSBkaW4gdmVjdG9yIGNhcmUgc3VudCBwcmltZSBjdSB1bHRpbXVsIGVsZW1lbnQgYWwgdmVjdG9ydWx1aS4KICAKICBJbnB1dDogCiAgUHJvZ3JhbXVsIGNpdGXImXRlIGRlIGxhIHRhc3RhdHVyxIMgbnVtxINydWwgbiwgaWFyIGFwb2kgbiBudW1lcmUgbmF0dXJhbGUsIHJlcHJlemVudMOibmQgZWxlbWVudGVsZSB2ZWN0b3J1bHVpCiAgT3V0cHV0OgogIFByb2dyYW11bCB2YSBhZmnImWEgcGUgZWNyYW4gdmFsb3JpbGUgY2VydXRlLCDDrm4gb3JkaW5lIGRlc2NyZXNjxIN0b2FyZSwgc2VwYXJhdGUgcHJpbiBleGFjdCB1biBzcGHIm2l1LgogIAogIFJlc3RyaWN0aWkgc2kgcHJlY2l6YXJpOgogICAgCiAgIC0gMSA8PSBuIDw9IDEwMDAKICAgCiAgIC0gY2VsZSBuIG51bWVyZSBjaXRpdGUgdm9yIGZpIG1haSBtaWNpIGRlY8OidCAxLjAwMC4wMDAuMDAwCiAgIApFeGFtcGxlOgoKCklucHV0OgogICAgIDgKICAgICAKICAgICAxNiA3IDYzICAxIDUgOSAxNCAKICAgICAKT3V0cHV0OgogICAgIDkgNSAzIDEKKi8gICAgIAoKCiNpbmNsdWRlIDxzdGRpby5oPgoKdm9pZCBjb3VudGluZ3NvcnQobG9uZyBsb25nICpwLCBpbnQgbikgewoKICAgICBsb25nIGxvbmcgQltuKzFdLCBDW24rMV0sIGksIGo7CgogICAgIGZvcihpID0gMDsgaSA8IG47ICsraSkgQ1tpXSA9IHBbaV07CgogICAgIGZvcihpID0gMDsgaSA8IG47ICsraSkgQltpXSA9IDA7CgogICAgIGZvcihpID0gMDsgaSA8IG4gLSAxOyArK2kpIHsKCiAgICAgICAgIGZvcihqID0gaSArIDE7IGogPCBuOyArK2opIHsKCiAgICAgICAgICAgICBpZihDW2ldIDwgQ1tqXSkgewoKICAgICAgICAgICAgICAgICBCW2ldKys7CgogICAgICAgICAgICAgfSBlbHNlIHsKCiAgICAgICAgICAgICAgICAgQltqXSsrOwogICAgICAgICAgICAgfQoKICAgICAgICAgfQogICAgIH0KCiAgICAgZm9yKGkgPSAwOyBpIDwgbjsgKytpKSBwW0JbaV1dID0gQ1tpXTsKIH0KCiBpbnQgZXVjbGlkKGludCBhLCBpbnQgYikgewogICAgIGludCByOwogICAgIHdoaWxlKGIpIHsKICAgICAgIHIgPSBhICUgYjsKICAgICAgIGEgPSBiOwogICAgICAgYiA9IHI7CiAgICAgfQogICAgIHJldHVybiBhOwogfQoKaW50IG1haW4oKSB7CgogICAgaW50IGksIGosIG4sIGsgPSAwOwoKICAgIHNjYW5mKCIlZCIsICZuKTsKCiAgICBsb25nIGxvbmcgYXJyW24rMV0sIGFycjJbbisxXTsKCiAgICBmb3IoaSA9IDA7IGkgPCBuOyArK2kpewoKICAgICAgICBzY2FuZigiJWxsZCIsICZhcnJbaV0pOwogICAgfQoKICAgZm9yKGkgPSAwOyBpIDwgbiAtIDE7ICsraSkgewoKICAgICAgIGlmKGV1Y2xpZChhcnJbaV0sIGFycltuLTFdKSA9PSAxKSB7CgogICAgICAgICAgIGFycjJbaysrXSA9IGFycltpXTsKICAgICAgIH0KICAgfQoKICAgIGNvdW50aW5nc29ydChhcnIyLCBrKTsKCiAgICBmb3IoaSA9IDA7IGkgPCBrOyArK2kpIHsKCiAgICAgICAgcHJpbnRmKCIlbGxkICIsIGFycjJbaV0pOwogICAgfQoKICAgIHJldHVybigwKTsKfQo=