bzoj 3629 [JLOI2014]聪明的燕姿——约数和定理+dfs
题目: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的更多相关文章
- BZOJ 3629 JLOI2014 聪明的燕姿 约数和+DFS
根据约数和公式来拆s,最后再把答案乘出来,我们发先这样的话递归层数不会太大每层枚举次数也不会太多,然而我们再来个剪枝就好了 #include<cstdio> #include<ios ...
- bzoj 3629: [JLOI2014]聪明的燕姿【线性筛+dfs】
数论+爆搜 详见这位大佬https://blog.csdn.net/eolv99/article/details/39644419 #include<iostream> #include& ...
- [BZOJ 3629][ JLOI2014 ]聪明的燕姿
这道题考试选择打表,完美爆零.. 算数基本定理: 任何一个大于1的自然数N,都可以唯一分解成有限个质数的乘积N=P₁^a₁ P₂^a₂…Pn^an,这里P₁<P₂<…<Pn均为质数, ...
- bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3629 [题意] 给定S,找出所有约数和为S的数. [思路] 若n=p1^a1*p2^a ...
- BZOJ_3629_[JLOI2014]聪明的燕姿_dfs
BZOJ_3629_[JLOI2014]聪明的燕姿_dfs Description 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 ...
- bzoj3629 / P4397 [JLOI2014]聪明的燕姿
P4397 [JLOI2014]聪明的燕姿 根据唯一分解定理 $n=q_{1}^{p_{1}}*q_{2}^{p_{2}}*q_{3}^{p_{3}}*......*q_{m}^{p_{m}}$ 而$ ...
- P4397 [JLOI2014]聪明的燕姿
P4397 [JLOI2014]聪明的燕姿 题目背景 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排 ...
- 【LG4397】[JLOI2014]聪明的燕姿
[LG4397][JLOI2014]聪明的燕姿 题面 洛谷 题解 考虑到约数和函数\(\sigma = \prod (1+p_i+...+p_i^{r_i})\),直接爆搜把所有数搜出来即可. 爆搜过 ...
- bzoj千题计划297:bzoj3629: [JLOI2014]聪明的燕姿
http://www.lydsy.com/JudgeOnline/problem.php?id=3629 约数和定理: 若n的标准分解式为 p1^k1 * p2^k2 …… 那么n的约数和= π (Σ ...
随机推荐
- cocos2d关于glew32.lib错误(转)
应项目需要使用cocos2d-x开发,又要学习新东东了.·cocos2d-x 是一个支持多平台的 2D 手机游戏引擎,用C++重写cocos2d-iphone引擎的一个开源项目,想了解更多的童鞋美去百 ...
- JQuery3 的新变化
1. for-of 循环 for-in 循环不被推荐遍历数组,forEach 循环不能中断,for-of 循环(ES6)则弥补了前两者的不足,又添加了更多拓展(比如能遍历字符串,DOM 元素等) 因此 ...
- 【收藏】SearchCrawler By James Holmes
转自Crawling the Web with Java By James Holmes 无需任何扩展包,可直接运行. import java.awt.*; import java.awt.event ...
- Python的装饰器实例用法小结
这篇文章主要介绍了Python装饰器用法,结合实例形式总结分析了Python常用装饰器的概念.功能.使用方法及相关注意事项 一.装饰器是什么 python的装饰器本质上是一个Python函数,它可以让 ...
- poj 1703 Find them, Catch them 【并查集 新写法的思路】
题目地址:http://poj.org/problem?id=1703 Sample Input 1 5 5 A 1 2 D 1 2 A 1 2 D 2 4 A 1 4 Sample Output N ...
- P2610 【[ZJOI2012]旅游】(dfs+树的直径)
楼下那篇题解说实话就是什么都没说,所以我再发一篇正常一点的. 楼下思路大体是正确的,但是之所以是说什么都没说,是因为他有两个比较致命的遗漏.首先是点,这里的点不是平时我们认为的点,如果多少接触过对偶图 ...
- [转载]Google Android开发精华教程
原文地址:Android开发精华教程">Google Android开发精华教程作者:huiyi8zai Android是Google于2007年11月5日宣布的基于Linux平台的开 ...
- QT 事件处理 KeyPressEvent 和 定时器时间 Timer
1. 按键事件响应, 两种方法,一种直接处理Event,过滤出KeyPress,另一种直接处理KeyPressEvent. bool Dialog::event(QEvent *e) { if( e- ...
- Codeforces Round #373 (Div. 2) E. Sasha and Array 矩阵快速幂+线段树
E. Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- v2.0 组件通信的总结
在vue.js现在比较流行,层出不穷的js框架越来越强调数据绑定,组件化开发. 正在给公司做一个管理后台,基本思路是编写几个通用组件,采用单页面应用的形式完成: 结构大致如下: mainVue lef ...