【LG4397】[JLOI2014]聪明的燕姿
【LG4397】[JLOI2014]聪明的燕姿
题面
题解
考虑到约数和函数\(\sigma = \prod (1+p_i+...+p_i^{r_i})\),直接爆搜把所有数搜出来即可。
爆搜过程和这道题一样,这里不再赘述。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX_N = 1e5 + 5;
int prime[MAX_N], num;
bool nprime[MAX_N];
void sieve() {
for (int i = 2; i <= 1e5; i++) {
if (!nprime[i]) prime[++num] = i;
for (int j = 1; j <= num && prime[j] * i <= 1e5; j++) {
nprime[prime[j] * i] = 1;
if (i % prime[j] == 0) break;
}
}
}
int Prime(int x) {
if (x <= 1e5) return !nprime[x];
for (int i = 1; i <= num && prime[i] * prime[i] <= x; i++)
if (!(x % prime[i])) return 0;
return 1;
}
int ans[MAX_N], cnt;
void solve(int S, int n, int lst) {
if (S - 1 > prime[num] && Prime(S - 1)) ans[++cnt] = n * (S - 1);
for (int i = lst; i; i--) {
int sum = 1, times = prime[i];
for (; sum + times <= S; ) {
sum += times;
if (S % sum == 0) solve(S / sum, n * times, i - 1);
if (1ll * times * prime[i] <= 1ll * S) times *= prime[i];
else break;
}
}
if (S == 1) ans[++cnt] = n;
}
int S;
int main () {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
freopen("cpp.out", "w", stdout);
#endif
sieve();
while (scanf("%d", &S) != EOF) {
cnt = 0;
solve(S, 1, num);
sort(&ans[1], &ans[cnt + 1]);
printf("%d\n", cnt);
for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
if (cnt) putchar('\n');
}
return 0;
}
【LG4397】[JLOI2014]聪明的燕姿的更多相关文章
- 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]聪明的燕姿 题目背景 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排 ...
- [JLOI2014]聪明的燕姿(搜索)
城市中人们总是拿着号码牌,不停寻找,不断匹配,可是谁也不知道自己等的那个人是谁. 可是燕姿不一样,燕姿知道自己等的人是谁,因为燕姿数学学得好!燕姿发现了一个神奇的算法:假设自己的号码牌上写着数字 S, ...
- bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3629 [题意] 给定S,找出所有约数和为S的数. [思路] 若n=p1^a1*p2^a ...
- bzoj3629[JLOI2014]聪明的燕姿
http://www.lydsy.com/JudgeOnline/problem.php?id=3629 搜索. 我们知道: 如果$N=\prod\limits_{i=1}^{m}p_{i}^{k_{ ...
- [BZOJ 3629][ JLOI2014 ]聪明的燕姿
这道题考试选择打表,完美爆零.. 算数基本定理: 任何一个大于1的自然数N,都可以唯一分解成有限个质数的乘积N=P₁^a₁ P₂^a₂…Pn^an,这里P₁<P₂<…<Pn均为质数, ...
- bzoj千题计划297:bzoj3629: [JLOI2014]聪明的燕姿
http://www.lydsy.com/JudgeOnline/problem.php?id=3629 约数和定理: 若n的标准分解式为 p1^k1 * p2^k2 …… 那么n的约数和= π (Σ ...
- 2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)
传送门 一道神奇的搜索. 直接枚举每个质因数的次数,然后搜索就行了. 显然质因数k次数不超过logkn" role="presentation" style=" ...
随机推荐
- thinkphp区间查询、统计查询、SQL直接查询
区间查询 $data['id']=array(array('gt',4),array('lt',10));//默认关系是(and)并且的关系 //SELECT * FROM `tp_user` WHE ...
- 本周学习总结(原生+Echarts地图)
本周主要想完成工作中大屏地图相关的知识,所以学习的时间不是很长 dsa.js(数据结构) 拖了两个星期还没看,等啥时候继续研究算法和数据结构再看源码 GoJS 有时间要好好研究下 https://gi ...
- Rabbit MQ 学习参考
网上的教程虽然多,但是提供demo的比较少,或者没有详细的说明,因此,本人就照着网上的教程做了几个demo,并把代码托管在码云,供有需要的参考. 项目地址:https://gitee.com/dhcl ...
- 第七节:EF Core调用SQL语句和存储过程
一. 查询类(FromSql) 1.说明 A. SQL查询必须返回实体的所有属性字段. B. 结果集中的列名必须与属性映射到的列名相匹配. C. SQL查询不能包含关联数据 D. 除Select以为的 ...
- What are regsvr32, regasm and gacutil using for?(转载)
What are regsvr32, regasm and gacutil using for? Regasm.exe is used to create COM Callable Wrapper ( ...
- 写一个TimeUI显示的函数,上代码
public void FreshDateTime() { string strWeek = string.Empty; #region 格式化星期 switch (DateTime.Now.DayO ...
- checkbox实现单选
脚本: function bb(obj,name) { var aa = document.getElementsByName(name); for (var i = 0; i < aa.len ...
- Python——全国瓜子二手车数据分析
继瓜子二手车数据爬去之后,在此进行处理分析 Pycharm代码 # coding:utf8 # author:Jery # datetime:2019/5/3 17:35 # software:PyC ...
- mask-rcnn解读(一):clip_boxes_graph
此部分为mask-rcnn中clip_boxes_graph()函数的使用.首先利用代码解决基本函数的使用,然后运行代码,其细节如下:代码如下: import tensorflow as tfimpo ...
- Python多任务—线程
并发:指的是任务数多余cpu核数,通过操作系统的各种任务调度算法,实现用多个任务“一起”执行(实际上总有一些任务不在执行,因为切换任务的速度相当快,看上去一起执行而已) 并行:指的是任务数小于等于cp ...