#include?
<
stdio.h
>
__int64??result;

__int64??gcd(?__int64?a,?__int64?b,?__int64
&
?x,?__int64
&
?y?)

{
????__int64?t,ret;

????
if
(?
!
b?)
{
????????x
=
?
1
,y
=
?
0
;
????????
return
?a;
????}
????
????ret
=
?gcd(?b,?a
%
?b,?x,?y?);
????t
=
?x,?x
=
?y,?y
=
?t
-
?a
/
?b
*
?y;
????
????
return
?ret;
}
bool
??f(?__int64?a,?__int64?b,?__int64?n?)

{
????__int64??d,?e,?x,?y,?i;
????
????d
=
?gcd(?a,?n,?x,?y?);
????
if
(?b
%
?d
!=
?
0
?)?
return
?
false
;
????
????result
=
?(?x
*
?(b
/
?d?)
%
?n
+
?n?)
%
?n;
????
return
?
true
;
}
int
?main()

{
????__int64?x,?y,m,n,l;
????
????
while
(?scanf(
"
%I64d%I64d%I64d%I64d%I64d
"
,
&
x,
&
y,
&
m,
&
n,
&
l)
!=
?EOF?)

????
{
????????
if
(?f(?n
-
?m,?x
-
?y,?l?)?)??printf(
"
%I64d\n
"
,?result?);
????????
else
??????????????????????printf(
"
Impossible\n
"
);
????}
????
????
return
?
0
;
}
posted on 2008-10-24 23:45
Darren 閱讀(820)
評論(0) 編輯 收藏 引用 所屬分類:
未分類