---
# System prepended metadata

title: j242. 111北二1a.自然數的平方根
tags: [資訊學科]

---

link：https://zerojudge.tw/ShowProblem?problemid=j242
```C++=
#include <stdio.h>
#include <cmath>
using namespace std;

int out_sq = 1, in_sq;

void break_down(){
    unsigned int i=2;
    int cnt = 0;
    int n = in_sq;
    const int std=sqrt(n);
    while (n>1 && i<=pow(2,31)-1){
        if (i>std && in_sq == n){
            break;
        }
        cnt = 0;
        while(n%i==0){
            n/=i;
            cnt++;
            if (cnt==2){
                in_sq/=i*i;
                out_sq*=i;
                cnt = 0;
            }
        }
        i++;
    }
}

int main()
{
    scanf("%d",&in_sq);
    break_down();
    if (out_sq==1) printf("sqrt(%d)",in_sq);
    else if (in_sq==1) printf("%d",out_sq);
    else printf("%d sqrt(%d)",out_sq,in_sq);
    

    return 0;
}
```