#include<bits/stdc++.h>
#include<string>
using namespace std;
string kiemtra(int n, int d)
{
string res;
map<int, int> mp;
mp.clear();
int rem = n % d;
while ((rem != 0) && (mp.find(rem) == mp.end()))
{
mp[rem] = res.length();
rem = rem * 10;
int res_part = rem /d;
res += to_string(res_part);
rem = rem % d;
}
return (rem == 0) ? "" : res.substr(mp[rem]);
}
int main()
{
double n,z; int a,b;
scanf("%d%d",&a,&b);
int m = a / b;
printf("%d ",m);
n = (double)a/b;
z = n - m;
string s = to_string(z);
s.erase(0,2);
while ( s.back()== '0')
s.pop_back();
string res = kiemtra(a, b);
if ( res == "")
{
cout << s;
} else cout << -1;
return 0;
}
Mong được sửa ạ