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 ...
随机推荐
- javascript 判断数据类型
Object.prototype.toString.call(asddfff) //报错asddfff没被定义Object.prototype.toString.call(undefined) //& ...
- css3实现头像旋转360度
css样式: .div a img{ width: 88px; height: 88px; border-radius: 88px; transition: all 1.2s ease-out 0s; ...
- c# 模拟get请求例子,演示Session会话状态。
创建一个控制台 程序: using System; using System.Collections.Generic; using System.IO; using System.IO.Compres ...
- 论文笔记:2018 PRCV 顶会顶刊墙展
Global Gated Mixture of Second-order Pooling for Imporving Deep Convolutional Neural Network(2018 NI ...
- Python实现在给定整数序列中找到和为100的所有数字组合
摘要: 使用Python在给定整数序列中找到和为100的所有数字组合.可以学习贪婪算法及递归技巧. 难度: 初级 问题 给定一个整数序列,要求将这些整数的和尽可能拼成 100. 比如 [17, 1 ...
- PLSQL入门:cursor传参,loop fetch使用,if使用,单引号字符表示
1.cursor传入参数 定义:cursor [cursor变量名称]([参数名称] [参数类型]) IS [SQL语句,可以使用传入参数] 例子: cursor moTypeNames(dom ...
- 升级到php7相关问题,日请求过亿QQ会员活动平台PHP7升级实践
升级到php7相关问题,日请求过亿QQ会员活动平台PHP7升级实践 日请求过亿:QQ会员活动平台PHP7升级实践http://mp.weixin.qq.com/s?__biz=MjM5MjAwODM4 ...
- MySQL笔记(四)DDL与DML风格参考
便于 COPY ▲ 在所有操作之前: SET character_set_database=utf8; 确保 ↓ mysql> SHOW VARIABLES LIKE "%char%& ...
- Web前端学习笔记之安装和使用PhantomJS
0x00 安装PhantomJS(linux环境安装) 将PhantomJS下载在/usr/local/src/packet/目录下(这个看个人喜好) 操作系统:CentOS 7 64-bit 1.下 ...
- spring MVC @Resource不支持Lazy加载及解决方法
今天迁一系统时发现有个bean使用@Resource注入了另外一个bean,这个被注入的bean是将被deprecated的类,而且只有一两个功能使用到,为了先调整进行测试,增加了@Lazy注解,启动 ...