Problem in printing A*B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int t;
    long long a,b;

    scanf("%d",&t);

    for(int i=1; i<=t; i++)
    {
        scanf("%lld %lld",&a,&b);
        printf("Case %d: %lld\n",i,a*b);
    }

    return 0;
}
Last edited on
Could you show the actual input and output of your program? Are you overflowing the long long when you multiply them together?
I see you recognize that you need an integer type that will support 10^18 i.e. 1000000000000000000, but what about when you have to multiply 2 of those numbers? What integer type will support 10^36 i.e. 1000000000000000000000000000000000000?

Also I have a feeling (Your Task is so simple...) you are not even supposed to evaluate the expression A * B, I think the problem is asking you to print literally "A * B" i.e. if you are given 2 numbers A = 10000000 and B = 1923123, your program should print "10000000 * 1923123". I could be wrong but it is worth the try
Last edited on
If it is automated then it is quite possible they want just a case number and the result.

So try:
printf("%d %lld\n",i,a*b);
Topic archived. No new replies allowed.