bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)
【题目链接】
http://www.lydsy.com/JudgeOnline/problem.php?id=3629
【题意】
给定S,找出所有约数和为S的数。
【思路】
若n=p1^a1*p2^a2*...*pk^ak
则约数和f(n)为(p1^0+p1+p1^2+...+p1^a1)*(p2^0+p2+p2^2+...+p2^a2)*...*(pk^0+pk+pk^2+...+pk^ak)
考虑搜索,使得和为S。至于这个搜索怎么写的,我能说我看不懂吗=_=
【代码】
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long ll;
const int N = 1e5+; ll su[N],vis[N]; ll ans[N]; void get_prime()
{
vis[]=;
for(int i=;i<N;i++) {
if(!vis[i]) su[++su[]]=i;
for(int j=;j<=su[]&&su[j]*i<N;j++) {
vis[i*su[j]]=;
if(i%su[j]==) break;
}
}
} bool is_prime(ll x)
{
if(x<N) return !vis[x];
for(ll i=;su[i]*su[i]<=x;i++)
if(x%su[i]==) return ;
return ;
} void dfs(ll now,int pos,ll left)
{
if(left==) {
ans[++ans[]]=now;
return ;
}
if( left->=su[pos] && is_prime(left-) )
ans[++ans[]]=(left-)*now;
for(int i=pos; su[i]*su[i]<=left ;i++) {
ll sum=su[i]+,pow=su[i];
for(;sum<=left;pow*=su[i],sum+=pow)
if(left%sum==)
dfs(now*pow,i+,left/sum);
}
} ll S; int main()
{
get_prime();
while(scanf("%lld",&S)!=EOF) {
ans[]=;
dfs(,,S);
sort(ans+,ans+ans[]+);
printf("%d\n",ans[]);
for(int i=;i<=ans[];i++)
printf("%lld%c",ans[i],i==ans[]?'\n':' ');
}
return ;
}
bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)的更多相关文章
- bzoj 3629 [JLOI2014]聪明的燕姿——约数和定理+dfs
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629 如果要搜索,肯定得质因数分解吧:就应该朝这个方向想. **约数和定理: 对于任意一个大 ...
- BZOJ 3629 JLOI2014 聪明的燕姿 约数和+DFS
根据约数和公式来拆s,最后再把答案乘出来,我们发先这样的话递归层数不会太大每层枚举次数也不会太多,然而我们再来个剪枝就好了 #include<cstdio> #include<ios ...
- [BZOJ 3629][ JLOI2014 ]聪明的燕姿
这道题考试选择打表,完美爆零.. 算数基本定理: 任何一个大于1的自然数N,都可以唯一分解成有限个质数的乘积N=P₁^a₁ P₂^a₂…Pn^an,这里P₁<P₂<…<Pn均为质数, ...
- bzoj 3629: [JLOI2014]聪明的燕姿【线性筛+dfs】
数论+爆搜 详见这位大佬https://blog.csdn.net/eolv99/article/details/39644419 #include<iostream> #include& ...
- 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})\),直接爆搜把所有数搜出来即可. 爆搜过 ...
- [JLOI2014]聪明的燕姿(搜索)
城市中人们总是拿着号码牌,不停寻找,不断匹配,可是谁也不知道自己等的那个人是谁. 可是燕姿不一样,燕姿知道自己等的人是谁,因为燕姿数学学得好!燕姿发现了一个神奇的算法:假设自己的号码牌上写着数字 S, ...
随机推荐
- player/stage 学习---安装
环境 ubuntu 14.04 一,工具安装 sudo apt-get install git cmake g++ fltk1.1-dev libjpeg8-dev libpng12-dev libg ...
- checkbox 全选、全不选、反选 插件
jquery.checkbox.js: ;(function($,window,document,undefined){ $.fn.check=function(mode){ mode= mode | ...
- 量化生产力Quantifying Productivity
I'm always on a lookout for interesting datasets to collect, analyze and interpret. And what better ...
- 写出完美论文的十个技巧10 Tips for Writing the Perfect Paper
10 Tips for Writing the Perfect Paper Like a gourmet meal or an old master painting, the perfect col ...
- linux源码Makefile详解
1.Makefile的作用 (1)决定编译哪些文件 (2)怎样编译这些文件 (3)怎样连接这些文件,最重要的是它们的顺序如何 2.Linux内核Makefile分类 ***************** ...
- apk反编译(6)ProGuard 工具 android studio版官方教程[作用,配置,解混淆,优化示例]
ProGuard In this document Enabling ProGuard (Gradle Builds) Configuring ProGuard Examples Decoding O ...
- trackr: An AngularJS app with a Java 8 backend – Part IV 实践篇
REST API对于前后端或后端与后端之间通讯是一个好的接口,而单页应用Single Page Applications (SPA)非常流行. 我们依然以trackr为案例,这是一个跟踪工作时间 请假 ...
- poj 1067 取石子游戏( 威佐夫博奕)
题目:http://poj.org/problem?id=1067 题意:有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的 ...
- codevs 1137 计算系数
什么时候NOIP也要出二项式定理了? 二项式定理+逆元. #include<iostream> #include<cstdio> #include<cstring> ...
- poj 3352 Road Construction
// 只能说这题和上题一模一样// 我就直接贴上题代码了.. #include <iostream> #include <algorithm> #include <que ...