Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <bits/stdc++.h>
- using namespace std;
- void func(int n) {
- int no = 1;
- int zerosCount = -1;
- while(no < n) {
- no *= 10;
- zerosCount += 1;
- }
- // cout<<no<<endl;
- vector<int> quotient;
- unordered_set<int> nos;
- nos.insert(no);
- int currentReminder;
- while(1) {
- quotient.push_back(no/n);
- currentReminder = no % n;
- no = currentReminder*10;
- while(no < n && no != 0) {
- no *= 10;
- quotient.push_back(0);
- }
- if(nos.find(no) != nos.end()) {
- break;
- }
- nos.insert(no);
- }
- cout<<"0.";
- for(int i = 0; i < zerosCount; i += 1) {
- cout<<0;
- }
- for(int i: quotient) {
- cout<<i;
- }
- cout<<" ";
- nos.clear();
- quotient.clear();
- nos.insert(no);
- while(1) {
- quotient.push_back(no/n);
- currentReminder = no % n;
- no = currentReminder*10;
- while(no < n && no != 0) {
- no *= 10;
- quotient.push_back(0);
- }
- if(nos.find(no) != nos.end()) {
- break;
- }
- nos.insert(no);
- }
- for(int i: quotient) {
- cout<<i;
- }
- cout<<endl;
- }
- int main()
- {
- vector<int> store = {2,3,4,5,6,7,8,9,11,13,17,19,23,25,27};
- for(int i: store) {
- func(i);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement