CF 2018 Battle of Brains GYM 102062 F
https://codeforces.com/gym/102062/attachments/download/8213/2018-battle-of-brains-en.pdf
https://codeforces.com/gym/102062
题意 对于一个数k 向自己的约数连一条无向边(不含1,和本身) ,递归每个约数进行相同的操作,最后构成树or图。
问 1-n有多少个数进行上述操作形成树。
解析 分析发现 将一个数质因数分解 当它有三个及以上质因数就是图,所以我们质数筛筛出来所有的素数标记为1,再两两相乘,小于1e6的标记为1
前缀和预处理答案就好了。
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
const int maxn = 1e6+;
const int inf = 0x3f3f3f3f;
const ll mod = ;
const double epx = 1e-;
const double pi = acos(-1.0);
//head------------------------------------------------------------------
int check[maxn],prime[maxn],pos,sum[maxn];
void Prime(int N)
{
pos=;
sum[]=;
for (int i = ; i <= N ; i++)
{
if (!check[i])
prime[pos++] = i,sum[i]=;
for (int j = ; j < pos && i*prime[j] <= N ; j++)
{
check[i*prime[j]] = ;
if (i % prime[j] == )
{
break;
}
}
}
}
int main()
{
Prime();
for(int i=;i<pos;i++)
{
for(int j=i;j<pos;j++) //根本不会超时 break是关键 虽然两层循环但是 o(n)的复杂度
{
if(1ll*prime[i]*prime[j]<=)
sum[prime[i]*prime[j]]=;
else
break;
}
}
for(int i=;i<=;i++)
sum[i]+=sum[i-];
int n,t,kase=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int d=__gcd(n,sum[n]);
printf("Case %d: %d/%d\n",kase++,sum[n]/d,n/d);
}
}
鸽了训练 去看电影了 哈哈。
CF 2018 Battle of Brains GYM 102062 F的更多相关文章
- Codeforces gym 102062 简要题解
文章目录 A. Bob and BoB B. Vibranium Gift C. The Blood Moon D. Palindrome and Chocolate E. Jumpy Robot F ...
- Gym 100637F F. The Pool for Lucky Ones
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- Gym 100637F F. The Pool for Lucky Ones 暴力
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100513F F. Ilya Muromets 线段树
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Codeforces Gym 100513F F. Ilya Muromets 水题
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...
- Gym - 100283F F. Bakkar In The Army —— 二分
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...
随机推荐
- iOS 第三方类库之MBProgressHUD
github链接地址 MBProgressHUD是一个开源的第三方类库实现了很多种样式的提示框,类似Activity indicator,使用上简单.方便,并且可以对显示的内容进行自定义,功能很强大, ...
- (53)zabbix模板
zabbix模板是做什么的? 平时工作中,我们需要监控web.mysql.redis.nginx这些服务器,众多服务器的业务都是一样的,所以我们只要事先创建好模板,然后所有服务器链接这个模板即可,如果 ...
- struct 区别 在C 和C++ 中
C语言中: Struct是用户自定义数据类型(UDT). C++语言中: Struct是抽象数据类型(ADT),支持成员函数的定义. 在C++中,struct的成员的默认访问说 ...
- 元组-tuple
Python内置的元组数据类型:tuple tuple和list非常类似,但tuple一旦初始化就不能修改,因此它没有append(),insert()这样的方法 当定义一个tuple时,tuple的 ...
- Ajax四步操作
第一步得到(XMLHttpRequest)function creatXMLHttpRequest(){ try{ return new XMLHttpRequest(); } catch(e){ t ...
- HDU 6447
YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- UVa 10534 DP LIS Wavio Sequence
两边算一下LIS就出来了,因为数据比较大,所以需要二分优化一下. #include <iostream> #include <cstdio> #include <cstr ...
- C#显示相机实时画面
public partial class Form1 : Form { ICogAcqFifo mAcqFifo2;//定义一个相机对象 private ICogFrameGrabber mFrame ...
- MFC下拉框
在函数OnInitDialog()中添加一下语句可以添加选项到下拉框中 m_comboBox.AddString(_T("ALKATIP Basma Tom")); m_combo ...
- OMS数据库调整1
一.增加2T存储空间 1. 对磁盘进行分区并格式化 [root@oms-db01 ~]# fdisk -l Disk /dev/sda: 322.1 GB, 322122547200 bytes 2 ...