Multiplication of long long & float

Thi question appeared in recent atcoder contest…
question link:C - Multiplication 3
This question is basic problem but took much time to get it,can any one please tell the clear concept of solving this problem

for the same problem my code is giving wrong answer can anyone tell me the mistake, Thanks.

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;

int main() {
long long A;
cin>>A;
float B;
cin>>B;
B=B*(100);
long long C=B;
long long ans=(A)*C;
ans=ans/100;
cout<<ans<<"\n";
return 0;
}

#include <cstdio>
#include <cmath>

using namespace std;

long long A, B;
int b1, b2;
long long ans;

int main() {
    scanf("%lld%d.%d", &A, &b1, &b2);
    B = b1 * 100 + b2;
    ans = (long long) (A * B) / 100;
    printf("%lld\n", ans);
    return 0;
}

This is the code in C++
You need to use long long in Cpp or long/BigInteger in JAVA
Please like

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        double B = sc.nextDouble();
        BigDecimal a = new BigDecimal(String.valueOf(A));
        BigDecimal b = new BigDecimal(String.valueOf(B));
        BigDecimal result = a.multiply(b);
        System.out.println(result.longValue());
    }
}

This is JAVA please like

Consider the test input:

873938008102648 4.43
1 Like

Oh ok i guess it’s because of that precision case right ? i mean we cant compare float number due to that slight plus minus. Like here 423.0 is not 432 its 432(+) or (-) x(for some small x).
If i am wrong please correct me.

Well no concept is required. Do as it is said, but take care of the precision. Here’s my code-

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
       ll a;
       long double b;
       cin>>a>>b;
       ll ans;
       ans=a*b;
       cout<<ans;
}

Thanks,but I have done same way it giving WA in first testcase of atcoder,dont know why???
try to submit again…u will know

if we use long long for A and long double for B is it enough??i am getting WA for that too… then what is the logic??

I did this and got AC

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;

int main() {
long long A;
cin>>A;
float B;
cin>>B;
B=B*(100);
long long C=(long long)round(B);
long long ans=(A)*C;
ans=ans/100;
cout<<ans<<"\n";
return 0;
}