can someone help me with this question?
question link - CodeChef: Practical coding for everyone
my approach is this. I’m not getting the answer.
thank you in advabce
#include<bits/stdc++.h>
typedef long long ll;
#define endl "\n"
using namespace std;
ll sum(ll n)
{
ll m,sum=0;
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
return sum;
}
void sol()
{
ll k,a,b;
cin>>k>>a>>b;// example - 6 10 7
long double x= (a/b);// 1
long double f= double(a)/ double(b); // 1.42857
long double removed_part = (f-x);// 1.42857 - 1 = 0.42857
long double ok =removed_part*pow(10,k); // 428571
string temp = to_string(ok); // in string 42857
string r = temp.substr(0, k); //extract the first k charcters
ll xx= stoll(r);// to int
cout<<sum(xx)<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int t=1;
cin>>t;
while(t--)
{
sol();
}
return 0;
}