Zeether

Ass2

Feb 6th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. COP 3223 – Section 3
  2.  
  3. Assignment 2: Acme Cryptography Division
  4.  
  5.  
  6.  
  7. Problem Statement
  8.  
  9.  
  10.  
  11. The executives at Acme like you, you’re a go-getter. You get things done. That’s why you’ve been promoted to the extremely secretive (and well paying) cryptography division of Acme Corporation.
  12.  
  13.  
  14.  
  15. One of the biggest modern encryption algorithms is RSA. It relies on the fact that numbers are difficult to factorize. “Factorizing numbers is easy,” you think to yourself. “I’ve been doing that since elementary school.” Now is your big chance to impress your co-workers with your programming prowess. You are going to write a program that takes in a series of integers, N, and prints out all pairs of numbers (a,b), such that a times b equals N, such that a is less than or equal to b, and a is not equal to 1. Furthermore, you will print out a special message if the number is a prime.
  16.  
  17.  
  18.  
  19.  
  20.  
  21. Input Specification
  22.  
  23.  
  24.  
  25. Input will begin with a line single integer, T (1 <T< 10). On each of the following T lines, there will be a single integer, N (2 <N< 10,000,000).
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. Output Specification
  34.  
  35.  
  36.  
  37. For each test case, your program should first print a case header. This will begin with
  38.  
  39.  
  40.  
  41. Case X: N
  42.  
  43.  
  44.  
  45. Where X is the case number (from 1 to T), and N is the number which will be factorized. After this line, print a single line for each pair (a,b) such that a is less than or equal to b, a is not equal to 1, and a times b equals N. These lines should have the following format
  46.  
  47.  
  48.  
  49. (a,b)
  50.  
  51.  
  52.  
  53. These lines should be printed in increasing order of a. Be careful to print each pair exactly once. Also, note that there is no space between the comma and the second factor.
  54.  
  55.  
  56.  
  57. If there are no valid pairs of numbers, the number must be a prime. In this event, print the following statement:
  58.  
  59.  
  60.  
  61. This number is a prime!
  62.  
  63.  
  64.  
  65. After each case, print a blank line. For further clarification, refer to the sample I/O.
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. Sample I/O
  74.  
  75.  
  76.  
  77. Input:
  78.  
  79.  
  80.  
  81. 4
  82.  
  83. 9
  84.  
  85. 10
  86.  
  87. 11
  88.  
  89. 12
  90.  
  91.  
  92.  
  93. Output:
  94.  
  95.  
  96.  
  97. Case 1: 9
  98.  
  99. (3,3)
  100.  
  101.  
  102.  
  103. Case 2: 10
  104.  
  105. (2,5)
  106.  
  107.  
  108.  
  109. Case 3: 11
  110.  
  111. This number is a prime!
  112.  
  113.  
  114.  
  115. Case 4: 12
  116.  
  117. (2,6)
  118.  
  119. (3,4)
  120.  
  121.  
  122.  
  123.  
  124.  
  125. NOTE: There is no space between the comma and the second factor
  126.  
  127.  
  128.  
  129. Deliverables
  130.  
  131.  
  132.  
  133. For your submission, please submit to webcourses2 a single file containing your source code. For scoring guidelines, please refer to the section labeled ‘Scoring Rubric’.
  134.  
  135.  
  136.  
  137. This assignment is due on webcourses2 at 11:59 PM, 12 February, 2013.
  138.  
  139.  
  140.  
  141.  
  142.  
  143. Scoring Rubric
  144.  
  145.  
  146.  
  147. This program is scored out of 20 points.
  148.  
  149.  
  150.  
  151. Coding Style (9) points
  152.  
  153. (1) Program contains a complete header comment (name, date, brief summary)
  154.  
  155. (1) Program maintains a reasonable use of whitespace
  156.  
  157. (1) Program uses clear, descriptive variable names
  158.  
  159. (1) Program reads in all values as integers
  160.  
  161. (1) Program contains a loop over T test cases
  162.  
  163. (1) Program contains a loop over N (or some function of N)
  164.  
  165. (1) Program does NOT prompt the user for input
  166.  
  167. (1) Program contains an if statement for handling the prime case
  168.  
  169. (1) Program contains at least one for loop
  170.  
  171.  
  172.  
  173. Correctness of Output (11) points (partial credit is possible)
  174.  
  175. (6) Printing of factor pairs
  176.  
  177. (1) Program prints out all possible pairs in at least one non-prime test case.
  178.  
  179. (1) Program prints out all possible pairs in most test cases
  180.  
  181. (1) Program prints out all possible pairs in all test cases
  182.  
  183. (1) Program does NOT print any duplicate factor pairs (i.e. (2,5) and (5,2))
  184.  
  185. (1) Program does NOT print the trivial pair (1,N)
  186.  
  187. (1) Program does NOT print any pairs where a times b does not equal N
  188.  
  189. (3) Formatting of factor pairs
  190.  
  191. (1) All factor pairs list the smaller number first
  192.  
  193. (1) Factor pairs are listed in increasing order of the smaller number
  194.  
  195. (1) Factor pairs are each printed on a separate line
  196.  
  197. (1) Program correctly prints the primality message in the prime case
  198.  
  199. (1) Text is exactly of the specified form. Remember to print a new line after each case
  200.  
  201.  
  202.  
  203. NOTE: Pay careful attention to follow the output guideline exactly (punctuation, case sensitivity etc).
Advertisement
Add Comment
Please, Sign In to add comment