<p> a,b의 범위가 굉장히 크기 때문에 전체 탐색으로 해결할 수 없습니다. 우선 어떠한 수가 홀수개의 약수만을 갖기위해선 그 수는 완전제곱수여야합니다. 그리고 [a,b]에서 a를 포함하지 않는 완전제곱수의 개수는 sqrt(b)-sqrt(a)입니다. 따라서 우리가 찾는 답은 c/d (c = sqrt(b)-sqrt(a), d = b-a) 입니다.이 분수를 기약분수로 만들기 위해서 분모와 분자를 분모와 분자의 최대공약수로 나누어주면 됩니다. 아래는 C++ 코드입니다. </p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #557799">
```{.cpp}
#include <<iostream> </span>
<span style="color: #557799">>
#include <<cstdlib> </span>
<span style="color: #557799">>
#include <<cstdio> </span>
<span style="color: #557799">>
#include <<cmath> </span>
<span style="color: #557799">>
#include <<algorithm> </span>
<span style="color: #008800; font-weight: bold">using</span> <span style="color: #008800; font-weight: bold">>
using namespace</span> std;<span style="color: #008800; font-weight: bold">typedef</span> <span style="color: #333399; font-weight: bold">long</span> <span style="color: #333399; font-weight: bold">long</span> ll;
ll <span style="color: #0066BB; font-weight: bold">gcd</span>(ll a,ll b){
<span style="color: #008800; font-weight: bold">if</span> (b <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>) <span style="color: #008800; font-weight: bold">return</span> a;
<span style="color: #008800; font-weight: bold">return</span> gcd(b,a<span style="color: #333333">%</span>b);
}
<span style="color: #333399; font-weight: bold">int</span> <span style="color: #0066BB; font-weight: bold">main</span>(){
ll a,b;
cin <span style="color: #333333">>></span> a <span style="color: #333333">>></span> b;
ll d <span style="color: #333333">=</span> b<span style="color: #333333">-</span>a;
ll c <span style="color: #333333">=</span> <span style="color: #333399; font-weight: bold">int</span>(sqrt(b))<span style="color: #333333">-</span><span style="color: #333399; font-weight: bold">int</span>(sqrt(a)); <span style="color: #888888">// 범위안에 약수의 개수가 홀수인 수의 개수 </span>
<span style="color: #008800; font-weight: bold">if</span> (c <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>) cout <span style="color: #333333"><<</span> <span style="color: #0000DD; font-weight: bold">0</span> <span style="color: #333333"><<</span> endl;
<span style="color: #008800; font-weight: bold">else</span>{
ll g <span style="color: #333333">=</span> gcd(c,d); <span style="color: #888888">// 기약분수로 만드는 과정 </span>
cout <span style="color: #333333"><<</span> (c<span style="color: #333333">/</span>g) <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"/"</span> <span style="color: #333333"><<</span> (d<span style="color: #333333">/</span>g) <span style="color: #333333"><<</span> endl;
}
<span style="color: #008800; font-weight: bold">return</span> <span style="color: #0000DD; font-weight: bold">0</span>;
}
</pre></div>typedef long long ll;
ll gcd(ll a,ll b){
if (b == 0) return a;
return gcd(b,a%b);
}
int main(){
ll a,b;
cin >> a >> b;
ll d = b-a;
ll c = int(sqrt(b))-int(sqrt(a)); // 범위안에 약수의 개수가 홀수인 수의 개수
if (c == 0) cout << 0 << endl;
else{
ll g = gcd(c,d); // 기약분수로 만드는 과정
cout << (c/g) << "/" << (d/g) << endl;
}
return 0;
}
```
<p> a,b의 범위가 굉장히 크기 때문에 전체 탐색으로 해결할 수 없습니다. 우선 어떠한 수가 홀수개의 약수만을 갖기위해선 그 수는 완전제곱수여야합니다. 그리고 [a,b]에서 a를 포함하지 않는 완전제곱수의 개수는 sqrt(b)-sqrt(a)입니다. 따라서 우리가 찾는 답은 c/d (c = sqrt(b)-sqrt(a), d = b-a) 입니다.이 분수를 기약분수로 만들기 위해서 분모와 분자를 분모와 분자의 최대공약수로 나누어주면 됩니다. 아래는 C++ 코드입니다. </p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #557799">
```{.cpp}
#include <<iostream> </span>
<span style="color: #557799">>
#include <<cstdlib> </span>
<span style="color: #557799">>
#include <<cstdio> </span>
<span style="color: #557799">>
#include <<cmath> </span>
<span style="color: #557799">>
#include <<algorithm> </span>
<span style="color: #008800; font-weight: bold">using</span> <span style="color: #008800; font-weight: bold">>
using namespace</span> std;<span style="color: #008800; font-weight: bold">typedef</span> <span style="color: #333399; font-weight: bold">long</span> <span style="color: #333399; font-weight: bold">long</span> ll;
ll <span style="color: #0066BB; font-weight: bold">gcd</span>(ll a,ll b){
<span style="color: #008800; font-weight: bold">if</span> (b <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>) <span style="color: #008800; font-weight: bold">return</span> a;
<span style="color: #008800; font-weight: bold">return</span> gcd(b,a<span style="color: #333333">%</span>b);
}
<span style="color: #333399; font-weight: bold">int</span> <span style="color: #0066BB; font-weight: bold">main</span>(){
ll a,b;
cin <span style="color: #333333">>></span> a <span style="color: #333333">>></span> b;
ll d <span style="color: #333333">=</span> b<span style="color: #333333">-</span>a;
ll c <span style="color: #333333">=</span> <span style="color: #333399; font-weight: bold">int</span>(sqrt(b))<span style="color: #333333">-</span><span style="color: #333399; font-weight: bold">int</span>(sqrt(a)); <span style="color: #888888">// 범위안에 약수의 개수가 홀수인 수의 개수 </span>
<span style="color: #008800; font-weight: bold">if</span> (c <span style="color: #333333">==</span> <span style="color: #0000DD; font-weight: bold">0</span>) cout <span style="color: #333333"><<</span> <span style="color: #0000DD; font-weight: bold">0</span> <span style="color: #333333"><<</span> endl;
<span style="color: #008800; font-weight: bold">else</span>{
ll g <span style="color: #333333">=</span> gcd(c,d); <span style="color: #888888">// 기약분수로 만드는 과정 </span>
cout <span style="color: #333333"><<</span> (c<span style="color: #333333">/</span>g) <span style="color: #333333"><<</span> <span style="background-color: #fff0f0">"/"</span> <span style="color: #333333"><<</span> (d<span style="color: #333333">/</span>g) <span style="color: #333333"><<</span> endl;
}
<span style="color: #008800; font-weight: bold">return</span> <span style="color: #0000DD; font-weight: bold">0</span>;
}
</pre></div>typedef long long ll;
ll gcd(ll a,ll b){
if (b == 0) return a;
return gcd(b,a%b);
}
int main(){
ll a,b;
cin >> a >> b;
ll d = b-a;
ll c = int(sqrt(b))-int(sqrt(a)); // 범위안에 약수의 개수가 홀수인 수의 개수
if (c == 0) cout << 0 << endl;
else{
ll g = gcd(c,d); // 기약분수로 만드는 과정
cout << (c/g) << "/" << (d/g) << endl;
}
return 0;
}
```