「JLOI2014」聪明的燕姿
传送门
Luogu
解题思路
很容易想到直接构造合法的数,但是这显然是会T飞的。
我们需要考虑这样一件事:
对于一个数 \(n\),对其进行质因数分解:
\]
那么就会有:
\]
可以证明 \(\sigma(n)\) 和 \(n\) 同级,所以这个质因子 \(p_i\le \sqrt{S}\),所以我们可以直接爆搜出来所有小于 \(\sqrt{S}\) 的质数,特判一下每一层dfs时的 \(S-1\) 是否为质数,然后算答案。
细节注意事项
- 爆搜题,你们懂得。。。
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
int vis[50000], num, prime[50000];
int cnt, ans[500000];
inline void seive() {
vis[1] = 1;
for (rg int i = 2; i < 50000; ++i) {
if (!vis[i]) prime[++num] = i;
for (rg int j = 1; j <= num && i * prime[j] < 50000; ++j) {
vis[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
}
inline bool isprime(int x) {
if (x <= 1) return 0;
if (x == 2) return 1;
for (rg int i = 2; i * i <= x; ++i)
if (x % i == 0) return 0;
return 1;
}
inline void dfs(int x, int i, int s) {
if (x == 1) { ans[++cnt] = s; return; }
if (isprime(x - 1) && x > prime[i]) ans[++cnt] = s * (x - 1);
for (rg int j = i; prime[j] * prime[j] <= x; ++j) {
int last = prime[j], sum = prime[j] + 1;
for (; sum <= x; last *= prime[j], sum += last)
if (x % sum == 0) dfs(x / sum, j + 1, s * last);
}
}
inline void solve(int x) {
if (x == 1) { puts("1"), puts("1"); return ; }
cnt = 0, dfs(x, 1, 1);
printf("%d\n", cnt);
sort(ans + 1, ans + cnt + 1);
for (rg int i = 1; i <= cnt; ++i)
printf("%d%c", ans[i], " \n"[i == cnt]);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
seive();
int n;
while (scanf("%d", &n) != EOF) solve(n);
return 0;
}
完结撒花 \(qwq\)
「JLOI2014」聪明的燕姿的更多相关文章
- LOJ #2234. 「JLOI2014」聪明的燕姿(搜索 + 数论)
题意 给出一个数 \(S\) ,输出所有约数和等于 \(S\) 的数. \(S \le 2 \times 10^9\) ,数据组数 \(\le 100\) . 题解 首先用约数和定理: \[ \beg ...
- BZOJ3629(JLOI2014)聪明的燕姿
(⊙﹏⊙)我交了好久,有坑啊...(如果没有匹配的话,即输出0种情况要记得换行...) 就是搜索,加上一点数论,并不太难... #include<cstdio> #include<c ...
- 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})\),直接爆搜把所有数搜出来即可. 爆搜过 ...
- AcWing1296. 聪明的燕姿
聪明的燕姿 解题思路: 首先我们肯定要用到约数之和定理 但是有个问题就是要怎么用 根据经验得知,约数最多也就六七个左右,不然直接就超了s的范围.所以我们考虑用爆搜来做 但是用爆搜的话还是要优化一下思路 ...
- 「JLOI2014」松鼠的新家
「JLOI2014」松鼠的新家 传送门 两种做法: 树上差分 \(O(n)\) 树链剖分 \(O(nlogn)\) 树剖比较好写而且无脑,树上差分复杂度优秀一些但是会有点难调. 这里给出树剖写法: 唯 ...
- 聪明的燕姿[JLOI2014]
题目描述 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排着队拿着爱的号码牌 城市中人们总是拿着号码牌 ...
随机推荐
- numpy.eye() 生成对角矩阵
numpy.eye(N,M=None, k=0, dtype=<type 'float'>) 关注第一个第三个参数就行了 第一个参数:输出方阵(行数=列数)的规模,即行数或列数 第三个参数 ...
- Introducing .NET 5
Today, we’re announcing that the next release after .NET Core 3.0 will be .NET 5. This will be the n ...
- Spring学习(九)
JdbcTemplate需要的jar包 1.Spring核心必须依赖的库:commons-logging-1.1.1.jar2.Spring IoC部分核心库: spring-beans-4.3.9. ...
- 吴裕雄 python 神经网络——TensorFlow 图像处理函数
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt image_raw_data = tf.gfile ...
- 02-12Android学习进度报告十二
今天学习了ListView的焦点问题,基本了解了ListView的使用内容. 首先可以为抢占了控件的组件设置:android:focusable="false" 只需为抢占了Lis ...
- 【PAT甲级】1042 Shuffling Machine (20 分)
题意: 输入洗牌次数K(<=20),输入54张牌每次洗入的位置(不是交换的位置),输出洗好的牌. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC ...
- 洛谷 T8088 RQY的舞会
嗯... 题目链接:https://www.luogu.org/problem/T8088 这道题很好想,我想的是维护两个小根堆(当然可以用数组模拟) 然后从堆顶开始,如果两个元素的差小于1,则cnt ...
- MVC集合ModelBinder
使用腳本提交集合类时,MVC binding public class FormExtensionValueProviderFactory : ValueProviderFactory { publi ...
- Java Web 前端资源文件的路径问题
WEB-INF是Java Web应用的安全目录,在部署时用于存放class文件.项目用到的库(jar包).Java Web应用的配置文件web.xml. 浏览器不能访问此目录下的资源,比如在WEB-I ...
- 最大流dinic板子
题目: https://www.luogu.com.cn/problem/P3376 #include <bits/stdc++.h> using namespace std; ; con ...