Advertisement
DennyGD

2-4-8

Jan 17th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. Problem 12-4-8
  2. Molly and Molly (yes, they have the same name) are two girls from the neighborhood. They like very much two games – one is singing the famous song “Molly, molly, molly…” and the other is sending encrypted SMS messages between each other so that their friends can never read them, no matter what.
  3. Molly and Molly communicate with a secret algorithm. It accepts three numbers, one of which is a secret code, defining a mathematical (don’t hate us, math is a universal language) function for the other two. Afterwards, a magic number 4 appears in the calculations and distorts the answer. Maybe you should start using this algorithm for your SMS messages too!
  4. You are given three numbers A, B, C, where B is actually the secret code symbol.
  5. If the code is 2 – find the remainder after A is divided by C. Example: A = 5, C = 3, A % C = 2.
  6. If the code is 4 – find the sum of A and C. Example: A = 5, C = 3, A + C = 8.
  7. If the code is 8 – find the product of A and C. Example: A = 5, C = 3, A * C = 15.
  8. After you find the result R from the code transformation, if R can be divided by 4 with remainder 0, find R divided by 4. Otherwise find the remainder after R is divided by 4.
  9. For example, if R is 16, it can be divided by 4 with no remainder, so the answer is 4. If R is 9, it cannot be divided by 4, so the answer is 1.
  10. Input
  11. The input data should be read from the console.
  12. On the first input line you will receive the positive integer A.
  13. On the second input line you will receive the positive integer B.
  14. On the third input line you will receive the positive integer C.
  15. The input data will always be valid and in the format described. There is no need to check it explicitly.
  16. Output
  17. The output should be printed on the console.
  18. If R can be divided by 4 with no remainder, on the first output line you should print R divided by 4.
  19. Otherwise, on the first output line you should print the remainder after R is divided by 4.
  20. On the second output line, you should print R.
  21. Constraints
  22. • A, B and C will be positive integers between 1 and 999 999, inclusive.
  23. • Allowed working time for your program: 0.10 seconds. Allowed memory: 16 MB.
  24.  
  25.  
  26.  
  27. Examples
  28. Input example   Output example
  29. 10
  30. 2
  31. 6   1
  32. 4
  33.  
  34. 6
  35. 4
  36. 3   1
  37. 9
  38.  
  39.  
  40. using System;
  41.  
  42. namespace _2_4_8
  43. {
  44.     class Program
  45.     {
  46.         static void Main()
  47.         {
  48.             long a = Int64.Parse(Console.ReadLine());
  49.             long b = Int64.Parse(Console.ReadLine());
  50.             long c = Int64.Parse(Console.ReadLine());
  51.             long r = 0;
  52.  
  53.             switch (b)
  54.             {
  55.                 case 2:
  56.                     r = a % c; break;
  57.                 case 4:
  58.                     r = a + c; break;
  59.                 case 8:
  60.                     r = a * c; break;
  61.             }
  62.  
  63.             long secondOutputLine = r;
  64.             if (r % 4 == 0)
  65.             {
  66.                 Console.WriteLine(r / 4);
  67.             }
  68.             else
  69.             {
  70.                 Console.WriteLine(r % 4);
  71.             }
  72.  
  73.             Console.WriteLine(secondOutputLine);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement