zcmu 2210 Trains(简单)

【题目】

2210: Trains

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: 13  Solved: 6
[Submit][Status][Web Board]

Description

A. Trains

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 (ab,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.

【题意】

读题有点困难qaq

输入a,b,当时间t%a==0时,Vasya去见Dasha;当t%b==0时,Vasya去见Masha;当t%a==0&&t%b==0时,Vasya去见见面次数比较少的女朋友。输出见面次数较多的女朋友的名字。

【思路】

只需要考虑时间[0,lcm(a,b)]即可。

【代码】

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define og(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b))
    {
        ll c=1ll*a/gcd(a,b)*b;
        int c1=c/a-1;
        int c2=c/b-1;
        if(c1<c2) c1++;
        else if(c1>c2) c2++;
        if(c1>c2) puts("Dasha");
        else if(c1<c2) puts("Masha");
        else puts("Equal");
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值