Codeforces Round 1027 (Div. 3)

ABCDE 略

F

记忆化搜索。首先让x和y除去他们的的gcd,此时x y互质。x经历除去所有它的约数到1,而y从1乘它所有的约数到y。本质一样。设f[x]表示x最少除以几个满足题意的数到1。这时一定有f[x]=min(f[x],f[x/y]+1)(y为x的约数且y<=k)。采用记忆化搜索,搜到一直接返回0。

#include 
using namespace std;
//#define int long long
#define endl '\n'
const int N=1e6+5;
int T,x,y,k,vis[N],f[N],id;
vector a[N];
void init()
{
}
int F(int x)
{
    if(vis[x]==id) return f[x];
	vis[x]=id;
	if(x==1) return f[x]=0;
	f[x]=1e7;
	for(int i=0;i>x>>y>>k;
    init();
    int t=__gcd(x,y);
    x/=t;y/=t;
    int temp=F(x)+F(y);
    if(temp>=1e7) cout<<-1<>T;
    while(T--) {id=T+1;solve();}
}

你可能感兴趣的:(Codeforces Round 1027 (Div. 3))