【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]聪明的燕姿的更多相关文章

  1. BZOJ_3629_[JLOI2014]聪明的燕姿_dfs

    BZOJ_3629_[JLOI2014]聪明的燕姿_dfs Description 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 ...

  2. bzoj3629 / P4397 [JLOI2014]聪明的燕姿

    P4397 [JLOI2014]聪明的燕姿 根据唯一分解定理 $n=q_{1}^{p_{1}}*q_{2}^{p_{2}}*q_{3}^{p_{3}}*......*q_{m}^{p_{m}}$ 而$ ...

  3. P4397 [JLOI2014]聪明的燕姿

    P4397 [JLOI2014]聪明的燕姿 题目背景 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排 ...

  4. [JLOI2014]聪明的燕姿(搜索)

    城市中人们总是拿着号码牌,不停寻找,不断匹配,可是谁也不知道自己等的那个人是谁. 可是燕姿不一样,燕姿知道自己等的人是谁,因为燕姿数学学得好!燕姿发现了一个神奇的算法:假设自己的号码牌上写着数字 S, ...

  5. bzoj 3629 [JLOI2014]聪明的燕姿(约数和,搜索)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3629 [题意] 给定S,找出所有约数和为S的数. [思路] 若n=p1^a1*p2^a ...

  6. bzoj3629[JLOI2014]聪明的燕姿

    http://www.lydsy.com/JudgeOnline/problem.php?id=3629 搜索. 我们知道: 如果$N=\prod\limits_{i=1}^{m}p_{i}^{k_{ ...

  7. [BZOJ 3629][ JLOI2014 ]聪明的燕姿

    这道题考试选择打表,完美爆零.. 算数基本定理: 任何一个大于1的自然数N,都可以唯一分解成有限个质数的乘积N=P₁^a₁ P₂^a₂…Pn^an,这里P₁<P₂<…<Pn均为质数, ...

  8. bzoj千题计划297:bzoj3629: [JLOI2014]聪明的燕姿

    http://www.lydsy.com/JudgeOnline/problem.php?id=3629 约数和定理: 若n的标准分解式为 p1^k1 * p2^k2 …… 那么n的约数和= π (Σ ...

  9. 2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)

    传送门 一道神奇的搜索. 直接枚举每个质因数的次数,然后搜索就行了. 显然质因数k次数不超过logkn" role="presentation" style=" ...

随机推荐

  1. POJ 3132 DP+素数筛

    Sum of Different Primes Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3684   Accepted ...

  2. C# 直接清空缓存方法

    注意要使用 HttpContext.Current.Cache.Remove(cacheKey); 不能使用 HttpRuntime.Cache[cacheKey]=null;

  3. ElasticSearch : High Rest Api 使用

    pom文件: <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId> ...

  4. SSM基本配置详解

    需要查看SSM基本依赖和完整配置文件的到:SSM基本配置及依赖 示例项目:SSMDemo 1 Spring IOC容器配置 1.1 applicationContext.xml 1.1.1 配置数据源 ...

  5. golang学习笔记 ---slice

    Go 语言中的slice类型可以理解为是数组array类型的描述符,包含了三个因素: 指向底层数组的指针 slice目前使用到的底层数组的元素个数,即长度 底层数组的最大长度,即容量 因此当我们定义一 ...

  6. [转] vue前端异常监控sentry实践

    1. 监控原理 1.1 onerror 传统的前端监控原理分为异常捕获和异常上报.一般使用onerror捕获前端错误: window.onerror = (msg, url, line, col, e ...

  7. Winfrom devexpress 通用权限框架

    毕业到现在也快两年了,手上的项目也有好几个,但总感觉不是狠理想,近来把手上杂七杂八的项目整理了一下,结合各个项目的优点,重新开发了一套winfrom+devexpress 通用权限(CS)框架(BS版 ...

  8. 浅聊几种主流Docker网络的实现原理

    原文:https://mp.weixin.qq.com/s/Jdxct8qHrBUtkUq-hnxSRw 参考:https://blog.csdn.net/yarntime/article/detai ...

  9. C#中 char、byte、string

    var str = "我是中国人";var str1 = "abc"; char[] chars = str.ToCharArray();char[] char ...

  10. SpringApplication到底run了什么(下)

    在上篇文章中SpringApplication到底run了什么(上)中,我们分析了下面这个run方法的前半部分,本篇文章继续开工 public ConfigurableApplicationConte ...