Loj 2047 伪光滑数

  • 正解较复杂,但这道题其实可以通过暴力解决.
  • 预处理出 \(128\) 内的所有质数,把 \(n\) 内的 \(prime[i]^j\) 丢进堆中,再尝试对每个数变形,除一个质因子,再乘一个.
  • 保证最大值因子的次数为正就可以了,取 \(k\) 次堆顶即得答案.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline ll read()
{
ll x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
ll n,k;
struct node{
ll a,b,c,d;
node(ll a,ll b,ll c,ll d):a(a),b(b),c(c),d(d) {}
bool operator < (const node &rhs) const
{
return a<rhs.a;
}
};
bool isp(ll x)
{
for(ll i=2;i*i<=x;++i)
if(x%i==0)
return false;
return true;
}
priority_queue<node> hp;
ll pr[130],cnt=0;
int main()
{
n=read(),k=read();
for(ll i=2;i<=128;++i)
{
if(isp(i))
{
pr[++cnt]=i;
ll a=1;
for(ll j=1;a<=n/i;++j)
{
a*=i;
hp.push(node(a,i,0,0));
if(cnt>1 && j>1)
hp.push(node(a/i*pr[cnt-1],i,j-1,cnt-1));
}
}
}
while(--k)
{
node cur=hp.top();
hp.pop();
ll a=cur.a,b=cur.b,c=cur.c,d=cur.d;
if(d>1)
hp.push(node(a/pr[d]*pr[d-1],b,c,d-1));
if(c>1)
hp.push(node(a/b*pr[d],b,c-1,d));
}
cout<<hp.top().a<<endl;
return 0;
}

最新文章

  1. 关于Onvif的event
  2. 3. Builder(建造者)
  3. TDD(测试驱动开发)培训录
  4. redis-string-统计
  5. spinner与arrays.xml的使用
  6. JavaScript中的setMonth()方法的小问题 解决:setMonth(month, 1)
  7. Web 在线文件管理器学习笔记与总结(7)重命名文件
  8. 如何在Qt 4程序中优化布局结构(表格讲解,很清楚)
  9. Android 使用PullToRefresh实现下拉刷新和上拉加载(ExpandableListView)
  10. 安卓升级提示 phoneGap APK软件更新提示
  11. hdu4280(最大流)
  12. ie6、ie7真的不支持inline-block吗?
  13. tkinter中text文本与scroll滚动条控件(五)
  14. balance.go 源码阅读
  15. 反编译Apk得到Java源代码
  16. Codeforces 1016 E - Rest In The Shades
  17. struts系列:校验(一)XML校验和函数方法校验
  18. UML-(团队作业)
  19. jquery.roundabout.js图片叠加3D旋转
  20. HttpClient 教程 (五)

热门文章

  1. SpringBoot项目结构介绍
  2. python 类和对象的属性
  3. shell脚本中case select 的使用
  4. VS2013 The Debugger Resource DLL is out of date
  5. Python之NumPy(axis=0 与axis=1)区分
  6. (新)自己动手写ORM框架(1)-增删查改的使用
  7. 【51nod-1138】连续整数的和
  8. SQL HAVING用法详解
  9. LeetCode OJ:Nim Game(Nim游戏)
  10. Redis数据结构:SDS