Codeforces Beta Round #73(Div2)补题报告

C - Trains

Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.

When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every a minutes, but a train goes to Masha's direction every b minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).

We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.

Help Vasya count to which girlfriend he will go more often.

Input

The first line contains two integers a and b (a ≠ b, 1 ≤ a, b ≤ 106).

Output

Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.

Examples

Input
3 7
Output
Dasha
Input
5 3
Output
Masha
Input
2 3
Output
Equal

Note

Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.

If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.

If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.

If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.

If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.

In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.

解题思路:求最小公倍数,

最小公倍数/a -1就是,除了特判的一个点外,去dasha的次数。

最小公倍数/b -1就是,除了特盘的点,去masha的次数。

最后比较一下。

ac代码:

#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
    while(b^=a^=b^=a%=b);
    return a;

}
int main(){
    int n,m,i,r,t1,t2;
    long long int res;
    cin>>n>>m;
    r=gcd(n,m);
    res=1ll*n/r*m;
    t1=res/n;
    t2=res/m;
    if(t1>t2){
        t2++;
    }
    else if(t2>t1){
        t1++;
    }
    if(t1==t2){
        puts("Equal");
    } 
    else if(t1>t2){
        puts("Dasha");
    }
    else{
        puts("Masha"); 
    } 
    return 0;
}
View Code

 

 

 

 

 

posted @ 2020-12-05 20:33  nanmoon  阅读(66)  评论(0编辑  收藏  举报