博客
关于我
bzoj 3629: [JLOI2014]聪明的燕姿
阅读量:258 次
发布时间:2019-03-01

本文共 1486 字,大约阅读时间需要 4 分钟。

求所有约数和等于S的数。

强大的dfs。

先要知道d是怎么求的。

d(n)=ki(1+p1+p2+p3+pa)
所以……直接上代码

void cal(int last,int tot,int num){    if(tot==1){ans[++n]=num;return;}    if(tot-1>sqrts&&isprime(tot-1))        ans[++n]=(tot-1)*num;    for(int i=last+1;prime[i]<=sqrts;i++)    {        int tmp=1,t=prime[i];         for (int j=1;tmp+t<=tot;j++)        {            tmp+=t;t*=prime[i];            if(tot%tmp==0)                cal(i,tot/tmp,num*(t/prime[i]));        }    }}

tot-1>sqrts是为了使选出来的数不重复,后面依次枚举 1+p,1+p+p2

最后排序,注意这题卡输出格式。
code:

#include
#include
#include
#include
#include
#include
#define LL long longusing namespace std;int prime[100010],pr=0;int sqrts,ans[1000010],n;bool v[100010];void pre(){ memset(v,true,sizeof(v)); for(int i=2;i<=100000;i++) { if(v[i]) prime[++pr]=i; for(int j=1;j<=pr&&i*prime[j]<=100000;j++) { v[i*prime[j]]=false; if(i%prime[j]==0) break; } }}bool isprime(int x){ if(x<=100000) return v[x]; int tmp=sqrt(x); for(int i=1;prime[i]<=tmp;i++) if(x%prime[i]==0) return false; return true;}void cal(int last,int tot,int num){ if(tot==1){ans[++n]=num;return;} if(tot-1>sqrts&&isprime(tot-1)) ans[++n]=(tot-1)*num; for(int i=last+1;prime[i]<=sqrts;i++) { int tmp=1,t=prime[i]; for (int j=1;tmp+t<=tot;j++) { tmp+=t;t*=prime[i]; if(tot%tmp==0) cal(i,tot/tmp,num*(t/prime[i])); } }}int main(){ int S;pre(); while(scanf("%d",&S)!=EOF) { sqrts=sqrt(S); n=0;cal(0,S,1); printf("%d\n", n); sort(ans+1,ans+n+1); for (int i=1;i

转载地址:http://gdza.baihongyu.com/

你可能感兴趣的文章
mysql deadlock found when trying to get lock暴力解决
查看>>
MuseTalk如何生成高质量视频(使用技巧)
查看>>
mutiplemap 总结
查看>>
MySQL DELETE 表别名问题
查看>>
MySQL Error Handling in Stored Procedures---转载
查看>>
MVC 区域功能
查看>>
MySQL FEDERATED 提示
查看>>
mysql generic安装_MySQL 5.6 Generic Binary安装与配置_MySQL
查看>>
Mysql group by
查看>>
MySQL I 有福啦,窗口函数大大提高了取数的效率!
查看>>
mysql id自动增长 初始值 Mysql重置auto_increment初始值
查看>>
MySQL in 太多过慢的 3 种解决方案
查看>>
MySQL InnoDB 三大文件日志,看完秒懂
查看>>
Mysql InnoDB 数据更新导致锁表
查看>>
Mysql Innodb 锁机制
查看>>
MySQL InnoDB中意向锁的作用及原理探
查看>>
MySQL InnoDB事务隔离级别与锁机制深入解析
查看>>
Mysql InnoDB存储引擎 —— 数据页
查看>>
Mysql InnoDB存储引擎中的checkpoint技术
查看>>
Mysql InnoDB存储引擎中缓冲池Buffer Pool、Redo Log、Bin Log、Undo Log、Channge Buffer
查看>>