Lab1_array
Lab1_array
Programming Assignment #1
Arrays
1. Problem Description
The greatest common divisor 𝑔𝑐𝑑(𝑎, 𝑏) between two positive integers 𝑎 and 𝑏
is defined as the largest positive integer that divides both 𝑎 and 𝑏 without a
remainder.
GCD is a very powerful tool in modern cryptography, and when the target integers
to be calculated are small (less than 108 ), GCD can be calculated in a few seconds with
a naïve method. However, the numbers in modern cryptography requires at least 512
digits to prevent attackers from using a brute-force method to derive the secret key. This
required number is too large for the naïve methods to calculate GCD in a reasonable
time and the numbers exceeds the limit of even long long in the C language. In this
problem, you will need to calculate the GCD of two big integers efficiently.
2. Input Format
One line containing two integers, 𝑎 and 𝑏, where 0 < 𝑎, 𝑏 < 10256 .
3. Output Format
An integer representing 𝑔𝑐𝑑(𝑎, 𝑏) with a single end-of-line (endl).
Sample Output 1
11
Sample Input 2
111111222222333333444444555555 666666777777888888999999
Sample Output 2
333333
5. Submission Information
1. Your program must be written in C/C++ language and can be compiled on the
Linux platform.
2. Please put the required files in a folder named with your Student_ID and the
required files should also be named with your Student_ID (.cpp, .c).
3. To submit your program, please use the command below to compress the folder
named with “[Student_ID].tar” in the Linux environment and upload it to E3.
tar cvf Student_ID.tar Student_ID
6. Due Date
Be sure to upload the tar file by “October 10, 2023”. There will be a 10% penalty per
day for the first four days (weekend included) and will not be accepted afterwards.
7. Grading Policy
The programming assignment will be graded based on the following rules:
˙ Pass the open cases with compilable source code (60%)
˙ Pass the hidden cases with compilable source code (40%)
˙ -10% of your total score if any file occurs naming error or not compress
˙ No credits for plagiarism
Hint
To deal with the big integers, we need a “data structure”, such as an integer array in C
to represent larger values. For instance, you can use an integer array where each element
represents one (decimal) digit, like representing 202309 by the following code snippet.
vector<int> digits = {9, 0, 3, 2, 0, 2};
It is not required to use the representation above, though. You can use any representation
that facilitates your implementation.