题目: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. 【HackerRank】Encryption

    One classic method for composing secret messages is called a square code.  The spaces are removed fr ...

  2. 以太坊钱包Geth使用命令

    一.启动以太坊钱包Geth 打开一个控制台,执行同步区块命令 #同步测试链geth --fast --cache=512 --rpc --rpcapi personal,db,eth,net,web3 ...

  3. linux中获取堆栈空间大小的方法

    #include   <stdio.h> #include   <stdlib.h> #include   <sys/time.h> #include   < ...

  4. Android LCD(二):常用接口原理篇【转】

    本文转载自:http://blog.csdn.net/xubin341719/article/details/9125799 关键词:Android LCD TFT TTL(RGB)  LVDS  E ...

  5. Go Mysql驱动

    Golang中MYSQL驱动 Mysql库https://github.com/go-sql-driver/mysql Go本身不提供具体数据库驱动,只提供驱动接口和管理. 各个数据库驱动需要第三方实 ...

  6. poj 2828 Buy Tickets 【买票插队找位置 输出最后的位置序列+线段树】

    题目地址:http://poj.org/problem?id=2828 Sample Input 4 0 77 1 51 1 33 2 69 4 0 20523 1 19243 1 3890 0 31 ...

  7. springmvc请求参数的绑定和获取

    请求参数的绑定和获取: 获取页面请求的参数,是javaweb必不可少的一个环节,在struts中,是通过再Action中定义属性,或者Model的方式进行数据绑定和获取.需要提供setter或gett ...

  8. 剑指Offer——字符串的排序

    Question 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入描 ...

  9. 域名注册中EAP期间是什么意思

    所谓域名申请期间的EAP指的是,域名优先注册期,行业上也称为“早期接入期”,这个期间的时间是由该域名所在的管理注册局定,而这个EPA期的时间长度也不一样,有的是一个星期,也有的长达两个星期. 域名EA ...

  10. tp后台注册登录配置项

    1.在application目录下Common/Conf/config.php中 2-17行,首先判断在data目录下有没有特意设置的db.php, config.php,route.php,如果有就 ...