http://pl.spoj.com/problems/PP0501A/2
mam problem z zadaniem powyżej
Nie działa mi przykład 48 100... wykazuje wynik 25. Podpowiecie co zrobiłem źle?
#include
using namespace std;
int nwd(int a, int b);
int main()
{
int liczba_testow;
cin>>liczba_testow;
for(int i=0; i<liczba_testow; i++)
{
int a,b;
cin>>a>>b;
cout<<nwd(a,b)<<endl;
}
return 0;
}
int nwd(int a, int b)
{
int wynik=0;
if(a==1 || b==1) wynik=1;
else if(a>b)
{
int x=1;
for(int i=0; i<b; i++)
{
if(a%x==0)
{
wynik=x;
}
x++;
}
}
else if(b>a)
{
int x=1;
for(int i=0; i<a; i++)
{
if(b%x==0)
{
wynik=x;
}
x++;
}
}
return wynik;
}
created
last reply
- 5
replies
- 551
views
- 3
users
- 1
link