http://www.lydsy.com/JudgeOnline/problem.php?id=3629

搜索。

我们知道:

如果$N=\prod\limits_{i=1}^{m}p_{i}^{k_{i}}$,其中$p_{i}$为质数,那么N的约数和为$\prod\limits_{i=1}^{m}(p_{i}^{0}+p_{i}^{2}+...+p_{i}^{k_{i}})$

如$36=2^{2}*3^{2}$,那么$36$的约数和为$(2^{0}+2^{1}+2^{2})*(3^{0}+3^{1}+3^{2})=91$

我们搜索找到所有合法最小的$p_{i}$和它次数$k_{i}$,然后DFS进入下一次搜索中。

如果发现当前的约数和为一个质数+1,我们可以加到答案去。

觉得答案的个数很少。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define fill(a,l,r,v) fill(a+l,a+r+1,v)
#define re(i,a,b) for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define ire(i,x) for(typedef(x.begin()) i=x.begin();i!=x.end();i++)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const int maxN=; int N=maxN;
int flag[maxN+];
int cnt,p[maxN+];
int S; int ge,out[maxN+]; inline int isprime(int v)
{
if(v<=N)return !flag[v];
int i;for(i=;i<=cnt && p[i]*p[i]<=v;i++)if(v%p[i]==)return ;
return ;
} inline void DFS(int last,int now,int tot)
{
if(tot==){out[++ge]=now;return;}
if(isprime(tot-) && tot->p[last])
out[++ge]=now*(tot-);
for(int i=last+;i<=cnt;i++)
for(int j=p[i],k=p[i]+;k<=tot;j=j*p[i],k+=j)
if(tot%k==)
DFS(i,now*j,tot/k);
} int main()
{
freopen("bzoj3629.in","r",stdin);
freopen("bzoj3629.out","w",stdout);
int i,j;
flag[]=;
re(i,,N)
{
if(!flag[i])p[++cnt]=i;
for(j=;j<=cnt && i*p[j]<=N;j++)
{
flag[i*p[j]]=;
if(i%p[j]==)break;
}
}
while(SF("%d\n",&S)!=EOF)
{
ge=;
DFS(,,S);
sort(out+,out+ge+);
ge=unique(out+,out+ge+)-out-;
PF("%d\n",ge);
re(i,,ge)PF("%d%c",out[i],i==ge?'\n':' ');
}
return ;
}

bzoj3629[JLOI2014]聪明的燕姿的更多相关文章

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

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

  2. 2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)

    传送门 一道神奇的搜索. 直接枚举每个质因数的次数,然后搜索就行了. 显然质因数k次数不超过logkn" role="presentation" style=" ...

  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. BZOJ_3629_[JLOI2014]聪明的燕姿_dfs

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

  6. P4397 [JLOI2014]聪明的燕姿

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

  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. sicily 4433 DAG?

    题意:输入一个有向图,判断该图是否是有向无环图(Directed Acyclic Graph). 解法:还是深搜 #include<iostream> #include<memory ...

  2. hadoop2.2.0 MapReduce的序列化

    package com.my.hadoop.mapreduce.dataformat; import java.io.DataInput;import java.io.DataOutput;impor ...

  3. JAVA的四种引用,强弱软虚用到的场景

    1.强引用 最常用的引用类型,如Object object = new Object(),只要强引用存在,GC必定 不回收,即使当前内存空间不足,jAVA虚拟机宁愿抛出OutofMemoryError ...

  4. [ES6] Module export

    Default export: Default export is easy way to export a function to outside module. //flash-message.j ...

  5. [React Testing] className with Shallow Rendering

    The React Shallow Renderer test utility lets us inspect the output of a component one level deep. In ...

  6. Qt使用AES加密算法对字符串进行加密

          因工作需要,需要对字符串进行加密处理,在网上找了很长时间,终于找到了一个可以使用的aes加密算法.其源代码采用c++编写而成,但其头文件引用windows.h,经过修改部分代码,将#inc ...

  7. netstat 命令详解

    netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的状态信息,在我的计算机上执行netstat后,其输出结果为:netstat命令是一 ...

  8. jquery向下取整

    var currentMoney =Math.round((_memberCurrentPoints/_pointVsMoney)*Math.pow(10,2))/Math.pow(10,2) * 2 ...

  9. ValidateBox( 验证框) 组件

    本节课重点了解 EasyUI 中 ValidateBox(验证框)组件的使用方法,这个组件依赖于Tooltip(提示框)组件. 一. 加载方式//class 加载方式<input id=&quo ...

  10. Access to the path '....' is denied.解决方法

    昨天公司项目迁移服务器,从自己服务器迁移到阿里云服务器,部署完成后发现有一个页面要读取磁盘上的静态文件就报错了... 如图: 解决办法: 在 Web.Config 的 <System.Web&g ...