Cod sursa(job #1997328)

Utilizator Alexandru_StoianStoian Sorin Alexandru Alexandru_Stoian Data 3 iulie 2017 22:23:01
Problema Divizori Primi Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<fstream>

using namespace std;

ifstream f ("divprim.in");
ofstream g ("divprim.out");

int n, i, k, x, ok, ap[ 100001 ], j;

int main(){

    for( i = 2; i <= 100001; ++i ){
        if( ap[ i ] == 0 ){
            for( j = i; j <= 100001; j = j + i )
            ap[ j ]++;
        }
    }
    f >> n;
    for( i = 1; i <= n; ++i ){
        f >> x >> k;
        ok = 0;
        for( j = x; j >= 1 && ok == 0; --j )
            if( ap[ j ] == k ){
                g << j << '\n';
                ok = 1;
            }
        if( ok == 0 )g << 0 << '\n';
    }

    return 0;
}