传送门

一道神奇的搜索。

直接枚举每个质因数的次数,然后搜索就行了。

显然质因数k次数不超过logkn" role="presentation" style="position: relative;">logknlogkn,因此搜索很快。

注意,如果最后剩下的乘积-1是一个质数,那么这是一个可行解。

另外对于这道题,我们只需要筛出1e5的素数就够了,太大的直接枚举自己打的素数表判就行了。

代码:

#include<bits/stdc++.h>
#define N 100005
using namespace std;
int pri[N],tot=0,s,cnt=0,ans[N];
bool vis[N];
inline void init(int len){
    for(int i=2;i<=len;++i){
        if(!vis[i])pri[++cnt]=i;
        for(int j=1;j<=cnt;++j){
            if(i*pri[j]>len)break;
            vis[i*pri[j]]=true;
            if(i%pri[j]==0)break;
        }
    }
}
inline bool check(int x){
    if(x==1)return false;
    if(x<=100000)return !vis[x];
    for(int i=1;pri[i]*pri[i]<=x;++i)if(x%pri[i]==0)return false;
    return true;
}
inline void dfs(int lastpri,int mul,int lim){
    if(lim==1){ans[++tot]=mul;return;}
    if(lim-1>pri[lastpri]&&check(lim-1))ans[++tot]=mul*(lim-1);
    for(int i=lastpri+1;pri[i]*pri[i]<=lim;++i){
        for(int mult=pri[i]+1,tmp=pri[i];mult<=lim;mult+=(tmp*=pri[i]))
            if(lim%mult==0)dfs(i,mul*tmp,lim/mult);
    }
}
int main(){
    init(100000);
    while(~scanf("%d",&s)){
        tot=0,dfs(0,1,s),printf("%d\n",tot),sort(ans+1,ans+tot+1);
        for(int i=1;i<=tot;++i)printf("%d%c",ans[i],i==tot?'\n':' ');
    }
    return 0;
}

2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)的更多相关文章

  1. bzoj3629[JLOI2014]聪明的燕姿

    http://www.lydsy.com/JudgeOnline/problem.php?id=3629 搜索. 我们知道: 如果$N=\prod\limits_{i=1}^{m}p_{i}^{k_{ ...

  2. bzoj千题计划297:bzoj3629: [JLOI2014]聪明的燕姿

    http://www.lydsy.com/JudgeOnline/problem.php?id=3629 约数和定理: 若n的标准分解式为 p1^k1 * p2^k2 …… 那么n的约数和= π (Σ ...

  3. bzoj3629 [JLOI2014]聪明的燕姿——DFS+约数和定理

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629 扫除了一个知识盲点:约数和定理 约数和定理: 对于一个大于1正整数n可以分解质因数:n ...

  4. bzoj3629 / P4397 [JLOI2014]聪明的燕姿

    P4397 [JLOI2014]聪明的燕姿 根据唯一分解定理 $n=q_{1}^{p_{1}}*q_{2}^{p_{2}}*q_{3}^{p_{3}}*......*q_{m}^{p_{m}}$ 而$ ...

  5. P4397 [JLOI2014]聪明的燕姿

    P4397 [JLOI2014]聪明的燕姿 题目背景 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排 ...

  6. BZOJ_3629_[JLOI2014]聪明的燕姿_dfs

    BZOJ_3629_[JLOI2014]聪明的燕姿_dfs Description 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 ...

  7. 【LG4397】[JLOI2014]聪明的燕姿

    [LG4397][JLOI2014]聪明的燕姿 题面 洛谷 题解 考虑到约数和函数\(\sigma = \prod (1+p_i+...+p_i^{r_i})\),直接爆搜把所有数搜出来即可. 爆搜过 ...

  8. [JLOI2014]聪明的燕姿(搜索)

    城市中人们总是拿着号码牌,不停寻找,不断匹配,可是谁也不知道自己等的那个人是谁. 可是燕姿不一样,燕姿知道自己等的人是谁,因为燕姿数学学得好!燕姿发现了一个神奇的算法:假设自己的号码牌上写着数字 S, ...

  9. bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3629 [题意] 给定S,找出所有约数和为S的数. [思路] 若n=p1^a1*p2^a ...

随机推荐

  1. grep命令打印前N行

    想打印前5行,用head即可:grep xxx |head -n 5

  2. UI5-文档-2.2-使用SAP Web IDE开发应用程序

    SAP Web IDE是一种基于Web的开发环境,它是为使用最新的创新开发SAPUI5复杂的应用程序.开发和扩展SAP Fiori应用程序.开发移动混合应用程序以及使用插件和模板扩展SAP Web I ...

  3. centos6.8 安装python2.7 or python3.6

    from:https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/ 准备 # Start by mak ...

  4. Redis need tcl 8.5 or newer

    hadoop@stormspark:~/workspace/redis2.6.13/src$ make testYou need tcl 8.5 or newer in order to run th ...

  5. iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 代码分层

    视频地址:https://www.cctalk.com/v/15114923889408 文章 在前面几节中,我们已经实现了项目中的几个常见操作:启动服务器.路由中间件.Get 和 Post 形式的请 ...

  6. hive sql 随机抽样

    create table daizk.IOS_matrix_sex asselect *from zhujx.1029_IOS_features_replce_nullwhere sex = 'M'u ...

  7. SQL 数据库事务 存储过程练习

    数据库事务: 数据库事务(Database Transaction) 是指作为单个逻辑工作单元执行的一系列操作. 事务处理可以确保除非事务性单元内的所有操作都成功完成,否则不会永久更新面向数据的资源. ...

  8. 在Ubuntu上安装微信

    1) 从https://github.com/geeeeeeeeek/electronic-wechat/releases地址中下载linux-x64.tar.gz文件到/opt/wechat文件夹 ...

  9. Win32 Debug & Release

    今天帮汤老师调试程序,他生成的程序不能运行,怀疑子程序之间编译顺序的问题:我试了之后,也出现同样的问题,但是把Win32 Debug 换成Win32 Release却可以运行了. 网上搜索了下,在CV ...

  10. tf.get_variable()

    1. tf.Variable()W = tf.Variable(<initial-value>, name=<optional-name>)1用于生成一个初始值为initial ...