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的约数和= π (Σ ...
随机推荐
- 主攻ASP.NET.4.5.1 MVC5.0之重生:政府行政网站常用友情链接跳转javascript[干货分享]
<!-----------------------------------> <script language="JavaScript" type="t ...
- Git常见命令整理
Git常见命令整理 + 注释 git init # 初始化本地git仓库(创建新仓库) git config --global user.name "xxx" # 配置用户名 gi ...
- jQuery仿苹果样式焦点图插件
在线演示 本地下载
- [转载]Runtime详解
Runtime的特性主要是消息(方法)传递,如果消息(方法)在对象中找不到,就进行转发,具体怎么实现的呢.我们从下面几个方面探寻Runtime的实现机制. Runtime介绍 Runtime消息传 ...
- Pandas的 loc iloc ix 区别
先看代码: In [46]: import pandas as pd In [47]: data = [[1,2,3],[4,5,6]] In [48]: index = [0,1] In [49]: ...
- 2018-02-11 发布 spring 自定义注解(annotation)与 aop获取注解
知识点: Java自定义注解.spring aop @aspect的使用 首先我们先介绍Java自定义注解. 在开发过程中,我们实现接口的时候,会出现@Override,有时还会提示写@Suppres ...
- 【bzoj1876】[SDOI2009]SuperGCD(高精度)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1876 一道简单的高精度+Stein算法(或者叫辗转相除法)求最大公约数板子题. md还 ...
- Exception in thread "main" java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for topic_test_1219-2: 30010 ms has passed since batch creatio
代码如下 public static void producer1() throws ExecutionException, InterruptedException { Properties pro ...
- struct2学习
struct1和webwork产生Struts2. struts2每次访问必定创建一个action,struts1只要一个action对象. Url中动态方法调用DMI 约定优于配置.miamhuai ...
- 我的博客搬家到https://www.w2le.com/了
大家以后想看我的博文的请到这里哦,欢迎大家访问https://www.w2le.com/