Cod sursa(job #1056202)
Utilizator | Marin Petcu utcn_petcu | Data | 14 decembrie 2013 12:41:28 |
---|---|---|---|
Problema | Progresie | Scor | 0 |
Compilator | cpp | Status | done |
Runda | ONIS 2014, Runda 1 | Marime | 0.74 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("cifre4.in");
ofstream g("cifre4.out");
int cifre(int x)
{
while (x)
{
if (x%10!=2 && x%10!=5 && x%10!=7 && x%10!=3)
return 0;
x/=10;
}
return 1;
}
int putere(int a,int b)
{
int i,x=a;
for (i=0;i<b-1;i++)
a=a*x;
return a;
}
int main()
{
int i,t,p,n,x,j,ok;
f>>t;
for (i=1;i<=t;i++)
{
f>>n>>p;
ok=1;
for (j=0;j<=10000000 && ok==1;j++)
{
x=p*j+n;
if(cifre(x))
{
ok=0;
g<<x<<'\n';
}
}
if (ok)
g<<-1<<'\n';
}
return 0;
}