UESTC 618 无平方因子数 ( 莫比乌斯)
题意:求1到n中无平方因子数的个数
Sample Input
3
1
10
30
Sample Output
1
7
19
思路:与前面的BZOJ 2440相似
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std; const int inf = 0x3f3f3f3f;
const int maxn = 1e6+10;
int tot;
int is_prime[maxn];
int mu[maxn];
int prime[maxn]; void Moblus()
{
tot = 0;
mu[1] = 1;
for(int i = 2; i < maxn; i++)
{
if(!is_prime[i])
{
prime[tot++] = i;
mu[i] = -1;
} for(int j = 0; j < tot && i*prime[j] < maxn; j++)
{
is_prime[i*prime[j]] = 1;
if(i % prime[j])
{
mu[i*prime[j]] = -mu[i];
}
else
{
mu[i*prime[j]] = 0;
break;
}
}
}
} int main()
{
Moblus();
int T;
ll n;
scanf("%d",&T);
while(T--)
{
ll ans = 0;
scanf("%lld",&n);
for(ll i = 1;i*i <= n;i++)
ans += (ll)mu[i]*(n/(i*i));
printf("%lld\n",ans);
}
}
UESTC 618 无平方因子数 ( 莫比乌斯)的更多相关文章
- uestc 1720无平方因子数
求素数 然后容斥原理// n之内有平方因子的数的个数sum =n/(2^2) + n/(3^2)+……+n/(k^2) - n/(2^2 * 3^2)-……+……. // #pragma commen ...
- cogs 2056. 无平方因子数
2056. 无平方因子数 ★☆ 输入文件:non.in 输出文件:non.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 给出正整数n,m,区间[n,m]内的无 ...
- CodeChef - SQRGOOD:Simplify the Square Root (求第N个含平方因子数)
Tiny Wong the chef used to be a mathematics teacher in a senior high school. At that time, he always ...
- ACM-ICPC 2018 南京赛区网络预赛 J sum (找一个数拆成两个无平方因子的组合数)
题目大意:就是找一个数拆成两个无平方因子的组合数,然后求个前缀和 ; 分析:运用筛法的思想 , 因为有序对是由两个合法的数字组成的,所以只要保证第一个数合法,第二个数也合法就行,找出合法的第二个数 ...
- 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)
J. Sum 26.87% 1000ms 512000K A square-free integer is an integer which is indivisible by any squar ...
- BZOJ2440(全然平方数)二分+莫比乌斯容斥
题意:全然平方数是指含有平方数因子的数.求第ki个非全然平方数. 解法:比較明显的二分,getsum(int middle)求1-middle有多少个非全然平方数,然后二分.求1-middle的非全然 ...
- UESTC - 618
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+11; const int N = 1e6; typed ...
- BZOJ 2440 中山市选2011 全然平方数 二分答案+容斥原理+莫比乌斯反演
题目大意:求第k个无平方因子数是多少(无视原题干.1也是全然平方数那岂不是一个数也送不出去了? 无平方因子数(square-free number),即质因数分解之后全部质因数的次数都为1的数 首先二 ...
- BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3028 Solved: 1460[Submit][Sta ...
随机推荐
- Faster R-CNN 的 RPN 是啥子?
 Faster R-CNN,由两个模块组成: 第一个模块是深度全卷积网络 RPN,用于 region proposal; 第二个模块是Fast R-CNN检测器,它使用了RPN产生的region p ...
- caffe使用ctrl-c不能保存模型
caffe使用Ctrl-c 不能保存模型: 是因为使用的是 tee输出日志 解决方法:kill -s SIGINT <proc_id> 或者使用 GLOG_log_dir=/path/to ...
- CentOS7 防火墙firewalld详细操作
1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disab ...
- jquery 表双击某行时,取出某行中各列的数值.
<script> $(function () { $("tr").dblclick(function () { var txt = $("table tr ...
- PHP冒泡排序、选择排序、插入排序
$arr = [1, 8, 7, 5, 4, 2, 11, 9, 20]; 冒泡排序: for ($i = 0; $i < count($arr); $i ++) { for ($j = 0; ...
- api-gateway实践(15)API网关的待改进点 20171207
一.API网关能力 API网关负责服务请求路由.组合及协议转换.客户端的所有请求都首先经过API网关,然后由它将请求路由到合适的微服务.API网关的客户端通过统一的网关接入微服务,在网关层处理所有的非 ...
- Angular 学习笔记 ( 链接服务器 )
ng 是做前端开发的, 所以通常我们会配上一个 API server. 本地调试时通常使用 proxy https://github.com/angular/angular-cli/blob/mast ...
- Ecplise 配置本地 https 测试
今天做项目,需要关联Office 365.为了实现Office365的用户邮件信息与项目的实时同步,需要建立webhook订阅. Office 365 API 连接 https://graph.mi ...
- Hibernat 原生SQL运行结果集处理方法
hibernate对原生SQL查询执行的控制是通过SQLQuery接口进行的. Session.createSQLQuery(); 使用list()方法可以把Session.createSQLQuer ...
- hdu 6205 card card card
https://vjudge.net/contest/184514#problem/L题意:排成一行的一堆牌,每堆牌都有一定数量的牌,然后每堆牌对应有一个惩罚值.一开始所有的牌都是正面向下的,并且在游 ...