hiho week 95 register

Ended

Participants:477

Verdict:Accepted
Score:100 / 100
Submitted:2016-04-29 21:06:39

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 <cstdio>
#include <cstring>
typedef long long ll;
ll gcd(ll a,ll b){
    ll t;
    while(t=a%b){
        a=b;
        b=t;
    }
    return b;
}
void ex_gcd(ll a,ll b,ll d,ll& x,ll& y){
    if(!b){
        d=a;
        x=1;
        y=0;
    }
    else{
        ex_gcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}
int main() {
    int s1,s2,v1,v2,m; 
    while(scanf("%d%d%d%d%d",&s1,&s2,&v1,&v2,&m)==5){
        ll a=v1-v2,b=m,c=s2-s1;
        if(a<0) a+=m;
        ll d=gcd(a,b);
        if(c%d){
            printf("-1\n");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX