Untitled
unknown
plain_text
2 months ago
1.0 kB
4
Indexable
#include <iostream> #include <fstream> using namespace std; ifstream fin (text.in); ofstream fout (text.out); void introducere_valori_arr(int nr, int arr[]) { for (int i = 2; i <= nr; i++) arr[i] = i; } void cerinta1(int n) { for (int i = 0; i < n; i++){ int nr, poz_div; cin >> nr >> poz_div; int arr[nr+1]; introducere_valori_arr(nr, arr); for (int a = 2; a <= nr; a++){ for(int b = 2; a*b <= nr; b++){ arr[a*b] = 0; } } int cnt_div = 0; for (int j = 2; j <= nr; j++){ if (arr[j] != 0){ if (nr % arr[j] == 0) cnt_div++; if (cnt_div == poz_div){ fout << arr[j] << " "; break; } } } } } int main() { int n, p; fin >> p >> n; if (p == 1) cerinta1(n); return 0; }
Editor is loading...
Leave a Comment