Question

For context this should be written in Python and I am looking for a unique solution,...

For context this should be written in Python and I am looking for a unique solution, not one copied from elsewhere online.

If the gcd(a,b) = 1, we say a and b are relatively prime. For any two relatively prime integers, there exist integers x and y such that ax + by = 1. This is called an example of a Linear Diophantine equation. Write a program that finds this x and y for each relatively prime pair.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • There is a module named diophantine in sympy package, specifically desgined to solve Linear diophantine equaitons.
  • diophantine equations have more than one solution. we can use base_solution_linear to get the principal soltuion

program

from sympy import symbols
from sympy.solvers.diophantine.diophantine import base_solution_linear

a = int(input("a = "))
b = int(input("b = "))


#solution for a*x + b*y = 1
sol = base_solution_linear(1, a, b,)
print(f"x = {sol[0]}\ny = {sol[1]}")

sample input and output:

la 17 b = 9 X = -1 ay = 2

Add a comment
Know the answer?
Add Answer to:
For context this should be written in Python and I am looking for a unique solution,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The code should be written with python. Question 1: Computing Polynomials [35 marks A polynomial is...

    The code should be written with python. Question 1: Computing Polynomials [35 marks A polynomial is a mathematical expression that can be built using constants and variables by means of addition, multiplication and exponentiation to a non-negative integer power. While there can be complex polynomials with multiple variable, in this exercise we limit out scope to polynomials with a single variable. The variable of a polynomial can be substituted by any values and the mapping that is associated with the...

  • Python Help Please! This is a problem that I have been stuck on.I am only suppose...

    Python Help Please! This is a problem that I have been stuck on.I am only suppose to use the basic python coding principles, including for loops, if statements, elif statements, lists, counters, functions, nested statements, .read, .write, while, local variables or global variables, etc. Thank you! I am using python 3.4.1. ***( The bottom photo is a continuation of the first one)**** Problem statement For this program, you are to design and implement text search engine, similar to the one...

  • Here I am asked to create a program using functions and files in python 3.7. I...

    Here I am asked to create a program using functions and files in python 3.7. I am unfortunately not able to use lists in the project. Thanks CSE 231 Fall 2019 Programming Project 05 This assignment is worth 45 points (4.5% of the course grade) and must be completed and turned in before 11:59 PM on Monday, October 14, 2019. Assignment Overview 1. Functions 2. File input and output 3. try-except Computational facial recognition is growing. Starting with the iPhone...

  • I am looking for toe menu "3" Ackermann table lookup function. IN JAVA I already made...

    I am looking for toe menu "3" Ackermann table lookup function. IN JAVA I already made my own menu, value, trace functions I just need table lookup function Ackermann's function Please create the following menu for the Ackermann project. This program allows you to call the Ackermann function. Please choose a version of Ackermann's Function. 1) Ackermann value. 2) Ackermann trace 3) Ackermann table lookup. 4) Quit playing with the Ackermann Function. Please choose one of the 4 choices Ackermann's...

  • I am stuck with this coding problem from edx coding python 4.4.6: #This is a long...

    I am stuck with this coding problem from edx coding python 4.4.6: #This is a long one -- our answer is 20 lines of code, but #yours will probably be longer. That's because it's one of the #more authentic problems we've done so far. This is a real #problem you'll start to face if you want to start creating #useful programs. # #One of the reasons that filetypes work is that everyone #agrees how they are structured. A ".png" file,...

  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

  • I have to use the following theorems to determine whether or not it is possible for...

    I have to use the following theorems to determine whether or not it is possible for the given orders to be simple. Theorem 1: |G|=1 or prime, then it is simple. Theorem 2: If |G| = (2 times an odd integer), the G is not simple. Theorem 3: n is an element of positive integers, n is not prime, p is prime, and p|n. If 1 is the only divisor of n that is congruent to 1 (mod p) then...

  • I would like some assistance correcting an issue I am having with this assignment. Once a...

    I would like some assistance correcting an issue I am having with this assignment. Once a finite state automaton (FSA) is designed, its transition diagram can be translated in a straightforward manner into program code. However, this translation process is considerably tedious if the FSA is large and troublesome if the design is modified. The reason is that the transition information and mechanism are combined in the translation. To do it differently, we can design a general data structure such...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • I need Summary of this Paper i dont need long summary i need What methodology they used , what is the purpose of this...

    I need Summary of this Paper i dont need long summary i need What methodology they used , what is the purpose of this paper and some conclusions and contributes of this paper. I need this for my Finishing Project so i need this ASAP please ( IN 1-2-3 HOURS PLEASE !!!) SPECIAL ARTICLES tole of Monetary Policy C Rangarajan What should be the objectives of monetary policy? Does the objective of price stability conflict with the goal of achieving...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT