UESTC 618

题意:求1到n中无平方因子数的个数

Sample Input



10 
30

Sample Output



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 无平方因子数 ( 莫比乌斯)的更多相关文章

  1. uestc 1720无平方因子数

    求素数 然后容斥原理// n之内有平方因子的数的个数sum =n/(2^2) + n/(3^2)+……+n/(k^2) - n/(2^2 * 3^2)-……+……. // #pragma commen ...

  2. cogs 2056. 无平方因子数

    2056. 无平方因子数 ★☆   输入文件:non.in   输出文件:non.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 给出正整数n,m,区间[n,m]内的无 ...

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

  4. ACM-ICPC 2018 南京赛区网络预赛 J sum (找一个数拆成两个无平方因子的组合数)

    题目大意:就是找一个数拆成两个无平方因子的组合数,然后求个前缀和  ; 分析:运用筛法的思想 ,  因为有序对是由两个合法的数字组成的,所以只要保证第一个数合法,第二个数也合法就行,找出合法的第二个数 ...

  5. 计蒜客 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 ...

  6. BZOJ2440(全然平方数)二分+莫比乌斯容斥

    题意:全然平方数是指含有平方数因子的数.求第ki个非全然平方数. 解法:比較明显的二分,getsum(int middle)求1-middle有多少个非全然平方数,然后二分.求1-middle的非全然 ...

  7. UESTC - 618

    #include<bits/stdc++.h> using namespace std; const int maxn = 1e6+11; const int N = 1e6; typed ...

  8. BZOJ 2440 中山市选2011 全然平方数 二分答案+容斥原理+莫比乌斯反演

    题目大意:求第k个无平方因子数是多少(无视原题干.1也是全然平方数那岂不是一个数也送不出去了? 无平方因子数(square-free number),即质因数分解之后全部质因数的次数都为1的数 首先二 ...

  9. BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]

    2440: [中山市选2011]完全平方数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3028  Solved: 1460[Submit][Sta ...

随机推荐

  1. 用java写一个servlet,可以将放在tomcat项目根目录下的文件进行下载

    用java写一个servlet,可以将放在tomcat项目根目录下的文件进行下载,将一个完整的项目进行展示,主要有以下几个部分: 1.servlet部分   Export 2.工具类:TxtFileU ...

  2. Linq 巧用 Max,Sum

    IList<, , , , , }; var sum1 = intList.Sum(s => { == ) { return s; } ; }); Console.WriteLine(&q ...

  3. 聊一聊C#的Equals()和GetHashCode()方法

    博客创建一年多,还是第一次写博文,有什么不对的地方还请多多指教. 关于这次写的内容可以说是老生长谈,百度一搜一大堆.大神可自行绕路. 最近在看Jeffrey Richter的CLR Via C#,在看 ...

  4. DSkin 的WebUI开发模式介绍,Html快速开发Winform的UI

    新版WebUI开发模式采用MiniBlink内核,这个内核功能更完善,dll压缩之后才5M,而且提供开发者功能,内核还在更新中,而且是开源项目:https://github.com/weolar/mi ...

  5. Python内置函数(46)——format

    英文文档: format(value[, format_spec]) Convert a value to a "formatted" representation, as con ...

  6. 新概念英语(1-11)Is this your shirt ?

    Is this your shirt?Whose shirt is white? A:Whose shirt is that? Is this your shirt, Dave? Dave:No si ...

  7. 启动mongodb遇到的错:warning: 32-bit servers don't have journaling enabled by deflity

    执行修复:mongod --repair即可 正常关闭:killall mongod

  8. 前端之JavaScript内容

    一.JavaScript概述 1.JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnv软件中),后将其改名ScriptEas ...

  9. ubuntu16.04下安装chrome

    1.在终端中,输入以下命令: sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.l ...

  10. CentOS7 安装eclipse

    1. 首先将eclipse的压缩包文件解压到/opt目录下,要使用root权限.执行如下解压命令:tar -zxvf eclipse-jee-oxygen-1a-linux-gtk-x86_64.ta ...