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的更多相关文章

  1. Codeforces gym 102062 简要题解

    文章目录 A. Bob and BoB B. Vibranium Gift C. The Blood Moon D. Palindrome and Chocolate E. Jumpy Robot F ...

  2. 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 ...

  3. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

  4. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  5. 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 ...

  6. Codeforces Gym 100513F F. Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  7. Codeforces Gym 100513F F. Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 利用VS自带的命令行工具查看和生产PublicKeyToken

    使用VS2008(或其他版本)命令行工具,键入:SN -T C:\*****.dll 就会显示出该dll具体的PublicKeyToken数值. 如果该程序集没有强命 名,则不会有PublicKeyT ...

  2. HTML5拖放(drag和drog)

    拖放(drag和drog)是HTML5的标准的组成部分,也是种常见的特性,意义为抓起一个元素放入到另外的一个位置,在HTML5中任何元素都可以被拖放,前题是要相关进行设置. 1.设置元素为可拖放,也就 ...

  3. 稳定性 耗时 gc 过长问题排查 和工具

    自己的另外一篇: http://www.cnblogs.com/fei33423/p/7805186.html 偶有耗时抖动? gc 也有长耗时? fullgc 也是? 有同学反馈 swap 可能导致 ...

  4. shell脚本,逻辑结构题练习。

    awk '/5/{a=1}!a' file2结果:1234解释:第一行 /5/不匹配跳过{a=1},继续!a,此时a没有值属于假取反为真,故输出第一行 第二行 /5/不匹配跳过{a=1},继续!a,此 ...

  5. shell脚本,编程题练习。

    题目是:将 文件file为 b+b+b+b+b+b+b+b 变为 b+b=b+b=b+b=b+b 解答方法如下:

  6. shell脚本,计算1+2+3+....100等于多少?

    第一种方法,通过for循环来计算[root@localhost wyb]# cat yibai.sh #!/bin/bash #从1+++...100的结果 i= ` do sum=$(($sum+i ...

  7. Dev-Cpp 5.11 c++编译器下载

    Dev-Cpp 5.11 c++编译器下载地址: 链接: https://pan.baidu.com/s/1jHMAf1k 密码: i6nw

  8. iOS UI 设计

    优设 http://www.uisdc.com Sketch http://www.sketchcn.com

  9. iOS开发遇到的坑之三--使用asi框架在xcode下正常运行,但是打包时却不能进行网络访问

    前言: 前两篇博客遇到的问题是前几天在实验室开发的时候遇到的,花了两三天时间在上面,今天突然心血来潮,想把这些”坑”写下来,所以才有了这两篇写的很丑的博客随笔 今天在开发时又遇到一个问题,那就是标题所 ...

  10. (9)zabbix创建监控项item

    1. 创建监控项 点击配置(configuration)->主机(Hosts)->在你要配置的主机一栏上点击Items->点击create item.具体看截图,各个参数我都已经标注 ...