首先证明 x * y = n + m
找到一个不能整除的点,然后合法进行构造。
这个贴了比人的代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m, x, y;
void work()
{
cin >> n >> m;
for(ll i = 1; i * i <= n + m; ++i)
{
if((m + n) % i) continue;
x = i, y = (n + m) / i;
}
if(x + y > 1e5) return puts("-1"), void();
ll sum = 0, cnt = 0, r = 0;
for(int i = 1; i <= x; ++i)
{
if(sum + y <= n) sum += y, ++cnt;
else {
r = n - sum;
break;
}
}
for(int i = 1; i <= cnt; ++i) cout << "R";
for(int i = 1; i <= y; ++i)
{
cout << "P";
if(r == y - i) cout << "R";
}
for(int i = cnt + 2; i <= x; ++i) cout << "R";
cout << endl;
}
int main()
{
ios::sync_with_stdio(0);
work();
return 0;
}