题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629

如果要搜索,肯定得质因数分解吧;就应该朝这个方向想。

**约数和定理:

对于任意一个大于1的正整数N可以分解正整数:N=P₁^a₁ P₂^a₂…Pn^an,则由约数个数定理可知N的正约数有(a+1)(a₂+1)(a₃+1)…(an+1)个,那么N(a₁+1)(a₂+1)(a₃+1)…(an+1)个正约数的和为f(N)=(P^0+P^1+P^2+…P^a)(P^0+P^1+P^2+…P^a)…(Pn^0+Pn^1+Pn^2+…Pn^an)

知道这个就可以枚举质因数和它们的指数,根据当前剩下的S进行dfs了。(唉,我竟然都不知道)

https://blog.csdn.net/eolv99/article/details/39644419

代码是跟着这个写的https://blog.csdn.net/PoPoQQQ/article/details/39152381(其实都一样?)

现在看来好像也就是这样罢了?自己还是经验不足(太蒟)。

(1e5?)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e5+,Mxn=2e9;
int p[N],tot,ans[N],num;
bool vis[N];
void get_pri()
{
for(int i=;i<=N;i++)//N is enough,not Mxn,or the array is not enough
{
if(!vis[i])p[++tot]=i;
for(int j=;j<=tot&&(ll)i*p[j]<=N;j++)
{
vis[i*p[j]]=;
if(i%p[j]==)break;
}
}
}
bool is_pri(int n)
{
if(n==)return false;//
for(int i=;p[i]*p[i]<=n;i++)
if(n%p[i]==)return false;
return true;
}
void dfs(int now,int pos,int left)
{
if(left==){ans[++num]=now;return;}
if(is_pri(left-)&&left->=p[pos])//>=,it > sqrt(left)
ans[++num]=(left-)*now; //这是只含一个的大于sqrt(left)的质数
for(int i=pos;i<=tot&&(ll)p[i]*p[i]<=left;i++)//其余质数有2个或以上
{
ll pwsum=p[i]+,pw=p[i];
for(;pwsum<=left;pw*=p[i],pwsum+=pw)//pwsum是定理,pw加到答案上
if(left%pwsum==)
dfs(now*pw,i+,left/pwsum);//i+1,not pos+1
}
}
int main()
{
get_pri();int n;
while(scanf("%d",&n)==)
{
num=;
dfs(,,n);printf("%d\n",num);
sort(ans+,ans+num+);
for(int i=;i<=num;i++)printf("%d%c",ans[i],i==num?'\n':' ');
}
return ;
}

bzoj 3629 [JLOI2014]聪明的燕姿——约数和定理+dfs的更多相关文章

  1. BZOJ 3629 JLOI2014 聪明的燕姿 约数和+DFS

    根据约数和公式来拆s,最后再把答案乘出来,我们发先这样的话递归层数不会太大每层枚举次数也不会太多,然而我们再来个剪枝就好了 #include<cstdio> #include<ios ...

  2. bzoj 3629: [JLOI2014]聪明的燕姿【线性筛+dfs】

    数论+爆搜 详见这位大佬https://blog.csdn.net/eolv99/article/details/39644419 #include<iostream> #include& ...

  3. [BZOJ 3629][ JLOI2014 ]聪明的燕姿

    这道题考试选择打表,完美爆零.. 算数基本定理: 任何一个大于1的自然数N,都可以唯一分解成有限个质数的乘积N=P₁^a₁ P₂^a₂…Pn^an,这里P₁<P₂<…<Pn均为质数, ...

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

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

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

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

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

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

  7. P4397 [JLOI2014]聪明的燕姿

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

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

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

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

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

随机推荐

  1. 使用Java实现八种基本排序

    插入排序.选择排序.冒泡排序.希尔排序.堆排序.快速排序.归并排序.基数排序 import java.util.ArrayList; import java.util.List; /** * 排序算法 ...

  2. box-flex兼容写法

    box-flex布局在这几年发生了多次变化,可分为2009版.2011版以及2013版, 区分: display:box(inline-box), box-{*}的格式为2009版 display:b ...

  3. Ubuntu 12.04下安装OpenCV 2.4.2

    http://sourceforge.net/projects/opencvlibrary/files/ Ubuntu 12.04下安装OpenCV 2.4.2 http://blog.csdn.ne ...

  4. 在Xcode中使用pch文件

    Xcode后面的版本不建议在开发时使用pch文件,但如果仍然需要使用pch文件可以这样配置: 1.用快捷键  [CMD] + N 新建文件,选 iOS下的 other->PCH File 2.p ...

  5. apache基于端口的虚拟主机配置

    主机ip: 192.168.7.51 Centos6.5 三个目录/usr/ftp/test/usr/ftp/dev/usr/ftp/demo 实现效果192.168.7.51:8052访问/usr/ ...

  6. Apache Phoenix的Join操作和优化

    估计Phoenix中支持Joins,对很多使用Hbase的朋友来说,还是比较好的.下面我们就来演示一下. 首先看一下几张表的数据: Orders表: OrderID CustomerID ItemID ...

  7. vue v-if with v-for

    遍历和条件判断混合使用示例. <!DOCTYPE html> <html> <head lang="en"> <meta charset= ...

  8. servlet中service() doGet() doPost() 方法

    HttpServlet 里的三个方法:service(HttpServletRequest req, HttpServletResponse resp) ,doGet(HttpServletReque ...

  9. 编写高质量代码——html、css、javascript

    [编写高质量代码]1.注释的必要性:增加代码的可读性.2.web标准:由一系列的标准组合而成,其核心理念是将网页的结构.样式.行为分离,所以他可分为:结构标准.样式标准和行为标准.3.一个符合标准的网 ...

  10. EDID真实数据块,请参考标准文档仔细核对

    数据格式的详细说明:http://en.wikipedia.org/wiki/Extended_display_identification_data 下面是一个例子: