### I_Love_Tourist_'s blog

By I_Love_Tourist_, history, 22 months ago,

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.

**Update** : Problem Solved

• -8

 » 22 months ago, # |   0 Auto comment: topic has been updated by I_Love_Tourist_ (previous revision, new revision, compare).
 » 22 months ago, # |   +12 SpoilerThe last $K$ digits of $N$ is just $N \,\%\, 10^K$.
 » 22 months ago, # | ← 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
•  » » 22 months ago, # ^ |   0 Clear now,tnx
•  » » 22 months ago, # ^ |   -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
•  » » » 21 month(s) ago, # ^ |   0 434500145 147276606 217842775 236387740it'll be WA.Ans is 00 , but it returns 0
•  » » » » 21 month(s) ago, # ^ |   +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.
•  » » » » » 21 month(s) ago, # ^ |   0 got it , Thanks
•  » » » » » 15 months ago, # ^ |   0 Thank you
 » 22 months ago, # |   +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$
•  » » 22 months ago, # ^ |   +3 thnks brother it is clear now
 » 22 months ago, # |   0 Below given is my solution You can check it. [submission:92942519]
•  » » 22 months ago, # ^ |   0 Solution is not open for this problem
•  » » » 19 months ago, # ^ |   0 can I pls have the solution attached here I tried a lot according to the instruction but for 792319479 461799503 958902232 930755956 I am getting output 44 not 04 where I gave the condition if n<10 pls help me
•  » » » » 18 months ago, # ^ |   0 int n, x, y, z; cin >> n >> x >> y >> z; int v = ((n%100)*(x%100)*(y%100)*(z%100))%100; if(v < 10) cout << 0 << v << "\n"; else cout << v << "\n";
•  » » » » » 18 months ago, # ^ |   0 upvote
•  » » » » » 18 months ago, # ^ |   0 does not work with x=y=z=n=1; it should print 1 instead.
•  » » » » » 18 months ago, # ^ | ← Rev. 2 →   0 can you explain this solution in the lines if(v < 10) cout << 0 << v << "\n"; else cout << v << "\n"; thank you i cant understand the logic
•  » » » » » » 18 months ago, # ^ |   0 for example if v = 810001 % 100. it gives you 1 but in the question we need last two digits. so we need to add 0 and it will be 01.In v = 810002 the last two digit is 02 but if we do 810002 % 100 it gives only 2.
 » 8 months ago, # | ← Rev. 2 →   -24 Spoilertrick with the compiler by a given 0
•  » » 8 months ago, # ^ |   +7 everyone waited 1 year to just see this answer lol
•  » » » 8 months ago, # ^ | ← Rev. 3 →   -24 it happens ;)
»
6 weeks ago, # |
0

# include <bits/stdc++.h>

using namespace std;

# define ll long long

int main() { ll a,b,c,d; cin >>a>>b>>c>>d; int v = ((a%100)*(b%100)*(c%100)*(d%100))%100;

if(v < 10){
cout << 0 << v << "\n";
}
else{
cout << v << "\n";
}
return 0;

}