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. win7上安装虚拟机并上网

    一.安装Workstation Pro 二.下载CentOS-7-x86_64-DVD-1511.iso包 三.创建新的虚拟机,按照向导安装即可 四.使用cd /etc/sysconfig/netwo ...

  2. Java产生GUID

    /** * 产生GUID */public static final String generateGUID(){ UUID uuid = UUID.randomUUID(); return uuid ...

  3. PAT (Basic Level) Practise (中文)-1030. 完美数列(25)

    PAT (Basic Level) Practise (中文)-1030. 完美数列(25)   http://www.patest.cn/contests/pat-b-practise/1030 给 ...

  4. oracle调用子存储过程+游标循环实例

    一,有子节点的部门的子节点的排序,调用子存储过程 CREATE OR REPLACE PROCEDURE "PRO_INIT_SORT" AS CURSOR cur_departm ...

  5. WebAssembly MDN简单使用

    MDN 就是通过编译器编译完成c后生成的胶水代码 引入js 就能直接调用定义在c或者c++中的函数了 c代码如下: #include <stdio.h> #include <stdl ...

  6. 使用Fiddler抓取IOS_APP的请求

    首先在地址https://www.telerik.com/fiddler 下载我们需要的fiddler 在新窗口中写上一些信息然后点击[Download for Windows]进行下载: 安装成功后 ...

  7. Apache安装错误 APR not found解决方法

    在配置Apache的时候,出现错误 原因是缺少一些依赖包,安装这些依赖包就行了 下载依赖包,注意我这里下载的与参考链接上的有些不同,安装上也有不一样 wget http://archive.apach ...

  8. 转载:jquery.ajax之beforeSend方法使用介绍

    常见的一种效果,在用ajax请求时,没有返回前会出现前出现一个转动的loading小图标或者“内容加载中..”,用来告知用户正在请求数据.这个就可以用beforeSend方法来实现. 下载demo:a ...

  9. Python的第3堂课

    20181119笔记 一.内存管理相关 ①Cpython解释器的垃圾回收机制 什么是垃圾:当一个值没有被绑定任何变量名(即该值的引用计数为零时),该值就是垃圾. 垃圾回收是收回值占用的内存空间. 引用 ...

  10. redis和memcached的优缺点及区别

    1. 使用redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...