Guest User

Untitled

a guest
Jul 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9. int n,k;
  10. int num[120];
  11. memset( num , 0 , 120) ;
  12. for(int u=0;u<120;u++)
  13. num[u]=0;
  14. while(cin>>n>>k)
  15. {
  16. for(int u=20;u<n+1;u++)
  17. {
  18. num[0]+=1/u;
  19. int lop=0,temp=1;
  20.  
  21. while(temp<u)
  22. { temp*=10;
  23. lop++;
  24. }
  25. while(temp!=0&&lop!=k+2&&u!=1)
  26. {
  27. while(temp<u)
  28. { temp*=10;
  29. lop++;
  30. }
  31. num[lop]+=temp/u;
  32. temp=temp%u;
  33. // lop++;
  34.  
  35. }
  36.  
  37. }
  38.  
  39. for(int u=k+1;u>0;u--)
  40. while(num[u]>9)
  41. {
  42. num[u-1]+=1;
  43. num[u]-=10;
  44. }
  45.  
  46. cout<<num[0]<<".";
  47. for(int u=1;u<k+1;u++)
  48. cout<<num[u]<<" ";
  49. cout<<"\n";
  50.  
  51. for(int u=0;u<k+1;u++)
  52. num[u]=0;
  53.  
  54.  
  55. }
  56. return 0;
  57. }
Add Comment
Please, Sign In to add comment