Mọi người cho e hỏi bài này chút với:
Bài của e để đây: https://ideone.com/rHCd21
#include<bits/stdc++.h>
using namespace std;
int compare(string a, string b){
while(a.size()<b.size()) a='0'+a;
while(b.size()<a.size()) b='0'+b;
if(a<b) return 1;
else if(a==b) return 0;
else return -1;
}
string sum(string a, string b){
int x,y,tong,nho=0;
string c="";
while(a.size()<b.size()) a='0'+a;
while(b.size()<a.size()) b='0'+b;
for(int i=a.size()-1;i>=0;i--){
x=a[i]-48;
y=b[i]-48;
tong=x+y+nho;
nho=tong/10;
c=char(tong%10+48)+c;
}
if(nho>0) c='1'+c;
return c;
}
string chia(string a, int k){
string t="";
int du=0;
int thuong;
for(int i=0;i<a.size();i++){
du=du*10+(a[i]-48);
thuong=du/k;
du=du%k;
t=t+char(thuong + 48);
}
while(t[0]=='0'&&t.size()>1) t.erase(0,1);
return t;
}
int mod(string a, int k){
int du=0;
for(int i=0;i<a.size();i++){
du=du*10+(a[i]-48);
du=du%k;
}
return du;
}
int main(){
string a;
int k;
cin >> a;
int d = 0;
for(string i = "1"; (compare(i,a)==1||compare(i,a)==0);i = sum(i, "1")){
while(mod(i,5)==0){
i=chia(i,5);
d++;
}
}
cout<<chia(a,5);
}
Chạy theo kiểu này nó cứ bị lỗi chỗ nào ý ạ, mọi người giúp e với!!!