hiho week 95 register

Ended

Participants:477

Verdict:Accepted
Score:100 / 100
Submitted:2016-04-28 21:50:49

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
int gcd(int a,int b);
using namespace std;
int main()
{
    int s1,s2,v1,v2,m;
    while(cin>>s1>>s2>>v1>>v2>>m)
    {
        int num=0;
        int A;
        A=v1-v2;
        int B=m;
        int C;
        C=s2-s1;
        int gc=gcd(A,B);
        if(C%gc!=0) cout<<-1<<endl;
        else
        {
         while(s1!=s2)
          {
            s1=s1+v1;
            s1=s1%m;
            s2=s2+v2;s2=s2%m;
            num++;
          }
          cout<<num<<endl;
        }
        
    }
}
int gcd(int a,int b)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX