Codeforces 448E - Divisors
思路:
dfs。注意如果是1,直接返回,因为1的因子还是1。
因为x因子的因子还是x的因子,所以可以事先处理好x因子的因子在x因子中的位置。
不用这个方法也可以,用map映射vector保存因子的因子。
代码1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem memset(a,b,sizeof(a)) const int N=1e6+;
vector<int>son[N];
vector<ll>t;
ll x;
int cnt=;
void dfs(ll k,ll n){
if(cnt==1e5)return ;
if(n==){
cout<<<<' ';
cnt++;
return ;
}
if(k==){
cout<<t[n]<<' ';
cnt++;
return ;
}else{
for(int i=;i<son[n].size();i++){
dfs(k-,son[n][i]);
if(cnt==1e5)return;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
ll k;
cin>>x>>k;
for(ll i=;i*i<=x;i++){
if(x%i==){
if(i*i==x)t.pb(i);
else t.pb(i),t.pb(x/i);
}
}
sort(t.begin(),t.end());
for(int i=;i<t.size();i++){
for(int j=;j<=i;j++)
if(t[i]%t[j]==)son[i].pb(j);
}
dfs(k,t.size()-);
return ;
}
代码2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem memset(a,b,sizeof(a)) vector<ll>t;
unordered_map<ll,vector<ll>>vc;
ll x;
int cnt=;
void dfs(ll k,ll n){
if(cnt==1e5)return ;
if(n==){
cout<<<<' ';
cnt++;
return ;
}
if(k==){
cout<<n<<' ';
cnt++;
return ;
}
else{
if(n==x){
for(int i=;i<t.size();i++){
dfs(k-,t[i]);
}
}else{
if(vc.find(n)!=vc.end()){
for(auto x:vc[n]){
dfs(k-,x);
if(cnt==1e5)return ;
}
}else{
for(ll i=;i*i<=n;i++){
if(n%i==){
if(i*i==n)vc[n].pb(i);
else vc[n].pb(i),vc[n].pb(n/i);
}
}
sort(vc[n].begin(),vc[n].end());
for(auto x:vc[n]){
dfs(k-,x);
if(cnt==1e5)return ;
}
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
ll k;
cin>>x>>k;
for(ll i=;i*i<=x;i++){
if(x%i==){
if(i*i==x)t.pb(i);
else t.pb(i),t.pb(x/i);
}
}
sort(t.begin(),t.end());
if(k==)cout<<x<<endl;
else if(k>=1e5){
if(x==)cout<<<<endl;
else{
for(int i=;i<=1e5;i++)cout<<<<' ';
cout<<endl;
}
}
else dfs(k,x);
return ;
}
Codeforces 448E - Divisors的更多相关文章
- [Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]
题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n ...
- [gcd]Codeforces Common Divisors
Common Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
- CodeForces - 27E--Number With The Given Amount Of Divisors(反素数)
CodeForces - 27E Number With The Given Amount Of Divisors Submit Status Description Given the number ...
- codeforces 703E Mishka and Divisors
codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...
- Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)
F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...
- Common Divisors CodeForces - 182D || kmp最小循环节
Common Divisors CodeForces - 182D 思路:用kmp求next数组的方法求出两个字符串的最小循环节长度(http://blog.csdn.net/acraz/articl ...
- codeforces 111B/112D Petya and Divisors
题目:Petya and Divisors传送门: http://codeforces.com/problemset/problem/111/B http://codeforces.com/probl ...
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
随机推荐
- js数组之迭代器方法
迭代器方法:对数组中的每一个元素应用一个函数,可以返回一个值,一组值或者一个新的数组.说的什么啊这是,根本听不懂.实践 不生成新数组的迭代器的方法: <html> <head> ...
- python 换行符的识别问题,Unix 和Windows 中是不一样的
关于换行符的识别问题,在Unix 和Windows 中是不一样的(分别是n 和rn).默认情况下,Python 会以统一模式处理换行符.这种模式下,在读取文本的时候,Python 可以识别所有的普通换 ...
- Hive 常用函数汇总
Hive内部提供了很多函数给开发者使用,包括数学函数,类型转换函数,条件函数,字符函数,聚合函数,表生成函数等等,这些函数都统称为内置函数. 目录 数学函数 集合函数 类型转换函数 日期函数 条件函数 ...
- bzoj1644 / P1649 [USACO07OCT]障碍路线Obstacle Course
P1649 [USACO07OCT]障碍路线Obstacle Course bfs 直接上个bfs 注意luogu的题目和bzoj有不同(bzoj保证有解,还有输入格式不同). #include< ...
- Linux 虚拟机安装vmware tools
Linux Vmware tools安装步骤 1 在 vSphere Client 清单中,右键单击虚拟机,然后选择电源 > 开启. 2 单击控制台选项卡以确定客户机操作系统启动成功,并在需 ...
- 20145302张薇 《网络对抗技术》 web基础
20145302张薇 <网络对抗> web基础 实验问题回答 1.什么是表单 表单在网页中主要负责数据采集功能:一般网页上需要用户输入.选择的地方都会用到表单 表单标签:即,用于确定表单所 ...
- USB/232/485/TTL/CMOS(串口通信)⭐⭐⭐
1.USB:电脑的USB口信号时USB信号,为差分信号,电压范围:+400mV~-400mV间变化:直流电压5V 驱动电流500MA 2.232电平: 逻辑1(MARK)=-3V--15V 逻辑0(S ...
- 在浏览器输入url后并回车发生了哪些过程
1.解析URL ________________________________________________________________________ 关于URL: URL(Universa ...
- VC++实现程序重启的方法(转载)
转载:http://blog.csdn.net/clever101/article/details/9327597 很多时候系统有很多配置项,修改了配置项之后能有一个按钮实现系统重启.所谓重启就是杀死 ...
- 奇怪的问题:改变了界面,生成的exe不起作用
现象:修改ui界面的控件,如改变text,生成exe没有改变,清理.重新创建也没有作用 原因:ui.h没有被更新,每次软件生成的时候都是调用的旧的文件 解决:先将debug和release文件夹删除, ...