码迷,mamicode.com
首页 > 其他好文 > 详细

青蛙的约会

时间:2015-02-11 21:49:20      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

扩展欧几里得

简单的经典题目

 

技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #define Mod 1000000007
 7 #define SMod 10007
 8 #define lll __int64
 9 #define ll long long
10 using namespace std;
11 #define N 1000007
12 
13 ll exgcd(ll a,ll b,ll &x,ll &y)
14 {
15     if(!b)
16     {
17         x = (ll)1,y = (ll)0;
18         return a;
19     }
20     ll r = exgcd(b,a%b,x,y);
21     ll t = x;
22     x = y;
23     y = t - a/b*y;
24     return r;
25 }
26 
27 ll gcd(ll a,ll b)
28 {
29     if(!b)
30         return a;
31     return gcd(b,a%b);
32 }
33 
34 int main()
35 {
36     ll x,y,m,n,L;
37     ll kx,ky;
38     while(scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&L)!=EOF)
39     {
40         ll nm = n-m;
41         ll delta = x-y;
42         if(nm < 0)
43         {
44             nm = m-n;
45             delta = y-x;
46         }
47         ll d = exgcd(nm,L,kx,ky);
48         if(delta%d)
49         {
50             puts("Impossible");
51             continue;
52         }
53         ll t = L/d;
54         //printf("%lld\n",t);
55         printf("%lld\n",res);
56     }
57     return 0;
58 }
代码君

 

青蛙的约会

标签:

原文地址:http://www.cnblogs.com/usedrosee/p/4286944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!