Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
competitive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Freitas Tissei
competitive
Commits
b9f0e47b
Commit
b9f0e47b
authored
5 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Add Linear Diophantine Equation
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
7c0e61f0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
algorithms/math/extended_euclidean.cpp
+1
-1
1 addition, 1 deletion
algorithms/math/extended_euclidean.cpp
algorithms/math/linear_diophantine_equation.cpp
+44
-0
44 additions, 0 deletions
algorithms/math/linear_diophantine_equation.cpp
caderno.pdf
+0
-0
0 additions, 0 deletions
caderno.pdf
with
45 additions
and
1 deletion
algorithms/math/extended_euclidean.cpp
+
1
−
1
View file @
b9f0e47b
/// Extended Euclidean algorithm
///
/// Time: O(log
n
)
/// Time: O(log
min(a,b)
)
/// Space: O(1)
struct
ExtendedEuclidean
{
...
...
This diff is collapsed.
Click to expand it.
algorithms/math/linear_diophantine_equation.cpp
0 → 100644
+
44
−
0
View file @
b9f0e47b
/// Linear Diophantine Equation
///
/// Description:
/// A Linear Diophantine Equation is an equation in the form $ax + by = c$.
/// A solution of this equation is a pair $(x,y)$ that satisfies the equation.
/// The locus of (lattice) points whose coordinates $x$ and $y$ satisfy the
/// equation is a straigh line. \par
/// The equation has a solution only if $gcd(a,b) | c$. In the case of
/// existing a solution for the provided $a, b, c$, the infinite set of
/// coordinates $(x,y)$ can be obtained with get(t) for
/// $t=...,-2,-1,0,1,2,...$.
///
/// Time: O(log min(a,b))
/// Space: O(1)
struct
Diophantine
{
int
a
,
b
,
c
,
d
;
int
x0
,
y0
;
bool
has_solution
;
Diophantine
(
int
a
,
int
b
,
int
c
)
:
a
(
a
),
b
(
b
),
c
(
c
)
{
init
();
}
void
init
()
{
ExtendedEuclidean
ext_gcd
;
int
w0
,
z0
;
d
=
ext_gcd
.
run
(
a
,
b
,
w0
,
z0
);
if
(
c
%
d
==
0
)
{
x0
=
w0
*
(
c
/
d
);
y0
=
z0
*
(
c
/
d
);
has_solution
=
true
;
}
else
{
has_solution
=
false
;
}
}
ii
get
(
int
t
)
{
if
(
!
has_solution
)
return
ii
(
inf
,
inf
);
return
ii
(
x0
+
t
*
(
b
/
d
),
y0
-
t
*
(
a
/
d
));
}
};
This diff is collapsed.
Click to expand it.
caderno.pdf
+
0
−
0
View file @
b9f0e47b
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment