Блог пользователя I_Love_Tourist_

Автор I_Love_Tourist_, история, 4 года назад, По-английски

Given 4 numbers A, B, C and D. Print the last 2 digits from their Multiplication.

Input : Only one line containing four numbers A, B, C and D (2 ≤ A,B,C,D ≤ 10^9).

Output : Print the last 2 digits from their Multiplication.

Problem link — here.

I found nothing by googling Please help me, i am a beginner so i don't know how to solve it.

Thanks in advance

**Update** : Problem Solved

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится
Spoiler
»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Take every number mod 100 and then multiply them to get rid of any large numbers. This works because (A * B * C * D) % 100 is equal to the last two digits (Try it yourself if you don't believe me) and because A % 100 * B % 100 * C % 100 * D % 100 is equal to (A * B * C * D) % 100, from properties of modular arithmetic

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится -7 Проголосовать: не нравится

    Little error here: A % 100 * B % 100 * C % 100 * D % 100 is equal to (A * B * C * D) % 100, you missed a % 100, it whould be like this: (A % 100 * B % 100 * C % 100 * D % 100)%100 is equal to (A * B * C * D) % 100

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      434500145 147276606 217842775 236387740

      it'll be WA.Ans is 00 , but it returns 0

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        This is something you should be careful with, the case where the tens digit is zero. We calculated both digits, but when you are printing 00 it will turn in to 0 and 01 in to 1. There is a simple fix: if the number is strictly less than 10 you print a 0 before.

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

It was already commented before, but the last two digits of a number $$$n$$$ is $$$n \% 100$$$. Just be careful when coding in laguages like C++ or C, because int and long long sizes are limited (int is always 32 bit and long long 64, don't use long). Python has a greater integer maximum, and that can make it easier to code in the naive way. If you are wondering how to code in C++ without BigNumber, you just need to observe that the last two digits aren't influentiated by digits more significant than the tens, for example:

$$$32 \times 27 = 864 $$$

and

$$$1232 \times 227 = 279664 $$$

As you can see the last two digits are the same, so this will be a simple formula for it:

$$$((A \% 100)(B\% 100)(C \% 100)(D \% 100))\%100$$$
»
2 года назад, # |
Rev. 2   Проголосовать: нравится -24 Проголосовать: не нравится
Spoiler