0%

CF-1027-F. Small Operations(通过选择1-K内的整数*和/使X==Y)

思路讲解

首先,遇到数论问题不要怕,我们人类其实对许多数论问题其实都束手无策,就靠计算机枚举。

那么,通过素因数分解,不难发现,我们可以把问题转化为这个。

💡 Note: 给你一个序列,比如说1,2,2,3,5,你要将这个序列删空,你一次可以选择任意多的数,只要这些数的乘积小于K。要求你找到一个方式,使用最少删除次数,告诉我这个次数。

那么其实经过素因数分解得出的序列是不会有 1 的。

image

把xrem除掉,再乘上yrem,就相等了。


记忆化搜索的时间复杂度那基本上等于 状态数×入口数量状态数\times入口数量,这里的状态数量其实就是因数的数量,入口数量也是因数数量,所以最坏情况下时间复杂度为 O(n23)O(n^{\frac{2}{3}})

image

这个super composite number 就是因数数量特别多的数,比比他小的所有数的因数都多,那么这样的数大概因数数量也就是 n3\sqrt[3]{n}

highly composite number is a positive integer that has more divisors than all smaller positive integers. If d(n) denotes the number of divisors of a positive integer n, then a positive integer N is highly composite if d(N) > d(n) for all n < N. For example, 6 is highly composite because d(6)=4, and for n=1,2,3,4,5, you get d(n)=1,2,2,3,2, respectively, which are all less than 4.

1
2
3
4
5
6
7
8
9
10
11
12
ll dfs(ll val){
if(dp[val]!=INF) return dp[val]+1;
if(val==1) return 1;
FOR(i,0,SZ(facs)-1){
ll fac=facs[i];
if(fac==1) continue;
if(fac>K) break;
if(val%fac==0) dp[val]=min(dp[val],dfs(val/fac));
}
return dp[val]+1;
}

那么问题的关键就在于减少入口,注意到只有因数是合法的。

AC代码

https://codeforces.com/contest/2114/submission/323597405

心路历程(WA,TLE,MLE……)