Cod sursa(job #2250200)

Utilizator ButumAndreiButum Andrei ButumAndrei Data 30 septembrie 2018 13:07:56
Problema Divizori Primi Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("divprim.in");
ofstream g("divprim.out");
int main()
{
    int n,k,x,nrd;
    f>>n;
    int j=0;
    while(j<n)
    {
        nrd=0;
        f>>x>>k;
        int i=1;

        int ok=1;
        while(ok==1)
        {nrd=0;
            int y=x-i;

            int yc=y;
            if(y%2==0)
            {
                nrd++;
                while(y%2==0)
                    y=y/2;
            }
            for(int d=3; d<=y; d++)
               {

                if(y%d==0)
                {
                    nrd++;
                    while(y%d==0)
                        y=y/d;
                }
               }



            if(nrd==k)
            {
                g<<yc<<endl;
                ok=0;
            }
            else if(nrd>k||nrd<k)
            { i++;
            if(yc==1)
             {g<<0<<endl;
                 ok=0;
             }

             }
        }
        j++;
    }
    f.close();
g.close();
    return 0;
}