Advertisement
venk

Untitled

Sep 22nd, 2022
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <bits/stdc++.h>
  10.  
  11. using namespace std;
  12.  
  13. void func(int n) {
  14.     int no = 1;
  15.     int zerosCount = -1;
  16.    
  17.     while(no < n) {
  18.         no *= 10;
  19.         zerosCount += 1;
  20.     }
  21.    
  22.     // cout<<no<<endl;
  23.    
  24.     vector<int> quotient;
  25.     unordered_set<int> nos;
  26.     nos.insert(no);
  27.     int currentReminder;
  28.    
  29.     while(1) {
  30.         quotient.push_back(no/n);
  31.         currentReminder = no % n;
  32.        
  33.         no = currentReminder*10;
  34.        
  35.         while(no < n && no != 0) {
  36.             no *= 10;
  37.             quotient.push_back(0);
  38.         }
  39.        
  40.         if(nos.find(no) != nos.end()) {
  41.             break;
  42.         }
  43.         nos.insert(no);
  44.     }
  45.    
  46.     cout<<"0.";
  47.    
  48.     for(int i = 0; i < zerosCount; i += 1) {
  49.         cout<<0;
  50.     }
  51.    
  52.     for(int i: quotient) {
  53.         cout<<i;
  54.     }
  55.     cout<<" ";
  56.    
  57.     nos.clear();
  58.     quotient.clear();
  59.    
  60.     nos.insert(no);
  61.    
  62.     while(1) {
  63.         quotient.push_back(no/n);
  64.         currentReminder = no % n;
  65.        
  66.         no = currentReminder*10;
  67.        
  68.         while(no < n && no != 0) {
  69.             no *= 10;
  70.             quotient.push_back(0);
  71.         }
  72.        
  73.         if(nos.find(no) != nos.end()) {
  74.             break;
  75.         }
  76.         nos.insert(no);
  77.     }
  78.    
  79.     for(int i: quotient) {
  80.         cout<<i;
  81.     }
  82.    
  83.     cout<<endl;
  84. }
  85.  
  86. int main()
  87. {
  88.    
  89.     vector<int> store = {2,3,4,5,6,7,8,9,11,13,17,19,23,25,27};
  90.    
  91.     for(int i: store) {
  92.         func(i);
  93.     }
  94.  
  95.     return 0;
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement