fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int compare(string a, string b){
  4. while(a.size()<b.size()) a='0'+a;
  5. while(b.size()<a.size()) b='0'+b;
  6. if(a<b) return 1;
  7. else if(a==b) return 0;
  8. else return -1;
  9. }
  10. string sum(string a, string b){
  11. int x,y,tong,nho=0;
  12. string c="";
  13. while(a.size()<b.size()) a='0'+a;
  14. while(b.size()<a.size()) b='0'+b;
  15. for(int i=a.size()-1;i>=0;i--){
  16. x=a[i]-48;
  17. y=b[i]-48;
  18. tong=x+y+nho;
  19. nho=tong/10;
  20. c=char(tong%10+48)+c;
  21. }
  22. if(nho>0) c='1'+c;
  23. return c;
  24. }
  25. string chia(string a, int k){
  26. string t="";
  27. int du=0;
  28. int thuong;
  29. for(int i=0;i<a.size();i++){
  30. du=du*10+(a[i]-48);
  31. thuong=du/k;
  32. du=du%k;
  33. t=t+char(thuong + 48);
  34. }
  35. while(t[0]=='0'&&t.size()>1) t.erase(0,1);
  36. return t;
  37. }
  38. int mod(string a, int k){
  39. int du=0;
  40. for(int i=0;i<a.size();i++){
  41. du=du*10+(a[i]-48);
  42. du=du%k;
  43. }
  44. return du;
  45. }
  46.  
  47.  
  48. int main(){
  49.  
  50. string a;
  51. int k;
  52. cin >> a;
  53. int d = 0;
  54. for(string i = "1"; (compare(i,a)==1||compare(i,a)==0);i = sum(i, "1")){
  55.  
  56. while(mod(i,5)==0){
  57. i=chia(i,5);
  58. d++;
  59. }
  60. }
  61. cout<<chia(a,5);
  62. }
  63.  
  64.  
Time limit exceeded #stdin #stdout 5s 4256KB
stdin
5
stdout
Standard output is empty