​Task6-Operation by Module-solution


#include <stdio.h>

using namespace std;

int main()
{
long long pro,ab,cd;     //It occupies 64 bits of memory
int  a,b,c,d,zbir,p3,z3;
scanf("%d%d%d%d",&a,&b,&c,&d);
    zbir=a+b+c+d;
    ab=a*b;                               //it multiplies two by two so that the data can cost as int i.e. in 32bits
    cd=c*d;
    pro=ab*cd;
    z3=zbir%1000;              //The rest of the division with 1000 are actually 3 last digits
    p3=pro%1000;
printf("%d %d",z3,p3);
    return 0;
}

Explanation

​ The numbers <999 can be declared as int, because they are not very large, but the product of such a number is
a number that is greater than 2 ^ 32 (2,147,483,647) which is the maximum value that can be taken by long data.
Therefore, the product must be declared long long, and it can accept the number <2 ^ 64​