Skip to content

Instantly share code, notes, and snippets.

@m-byte918
Created September 13, 2017 18:31
Show Gist options
  • Save m-byte918/d047da22a401a5a309093f0eb1ac716c to your computer and use it in GitHub Desktop.
Save m-byte918/d047da22a401a5a309093f0eb1ac716c to your computer and use it in GitHub Desktop.
#include <iostream>
int main() {
while (true) {
int outsideRoot;
int insideRoot;
int d = 2;
std::cout << "input outside root (if none, input 1)\n";
std::cin >> outsideRoot;
std::cout << "input inside root\n";
std::cin >> insideRoot;
while (d * d <= insideRoot) {
if (insideRoot % (d * d) == 0) {
insideRoot = insideRoot / (d * d);
outsideRoot = outsideRoot * d;
} else {
d = d + 1;
}
}
std::cout << "the answer is: " << outsideRoot << "√" << insideRoot << "\n";
std::cout << "------------------------\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment