求素数  然后容斥原理
// n之内有平方因子的数的个数sum =n/(2^2) + n/(3^2)+……+n/(k^2) - n/(2^2 * 3^2)-……+…….
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MOD 1000000007
#define maxn 1000010
#define maxm 1000010
#define LL long long
LL pr[maxn];
int p;
void getprime(){
int i,j;
for(i=;i<maxn;i+=) pr[i]=;
for(i=;i*i<maxn;i+=)
if(!pr[i])
for(j=i*i;j<maxn;j+=i)
pr[j]=;
pr[p++]=;
for(i=;i<maxn;i+=)
if(!pr[i])pr[p++]=i;
}
LL n,m,sum;
void dfs(int id,int dep,LL ji){
LL tp;
int i;
for(i=id;i<p;i++){
tp=ji*pr[i];
if(tp>m) return;
if(dep%)
sum+=n/(tp*tp);
else
sum-=n/(tp*tp);
dfs(i+,dep+,tp);
}
}
int main(){
getprime();
int T;
scanf("%d",&T);
while(T--){
// scanf("%I64d",&n);
scanf("%lld",&n);
m=sqrt(n+1.0);
sum=;
dfs(,,);
// printf("%I64d\n",n-sum);
printf("%lld\n",n-sum);
}
}

uestc 1720无平方因子数的更多相关文章

  1. UESTC 618 无平方因子数 ( 莫比乌斯)

    UESTC 618 题意:求1到n中无平方因子数的个数 Sample Input 3  1  10  30 Sample Output 1  7  19 思路:与前面的BZOJ 2440相似 #inc ...

  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. BZOJ 2440 中山市选2011 全然平方数 二分答案+容斥原理+莫比乌斯反演

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

  7. [SPOJ] DIVCNT2 - Counting Divisors (square) (平方的约数个数前缀和 容斥 卡常)

    题目 vjudge URL:Counting Divisors (square) Let σ0(n)\sigma_0(n)σ0​(n) be the number of positive diviso ...

  8. HDU 5778 abs (BestCoder Round #85 C)素数筛+暴力

    分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平 ...

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

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

随机推荐

  1. 将web应用打成war包发布到服务器

    如何将web应用打成war应用发布到服务器步骤: (1)先有一web应用"google"在C:盘下,如图: google下目录有WEB-INF文件夹(下有classes.lib.w ...

  2. 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台

    经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...

  3. Eclipse Error: Unable to set localhost. This prevents creation of a GUID.

    Symptoms The following error appears in the atlassian-confluence.log: 2011-03-16 18:20:03,021 ERROR ...

  4. android 使用sqlite的一些注意事项

    ①在Activity里创建SQLiteOpenHelper对象时,不要在成员变量里面传入context参数,而要在onCreate里面创建这个SQLiteOpenHelper对象.因为如果在成员变量里 ...

  5. CKeditor 配置使用

    CKeditor 配置使用 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="text/javascrip ...

  6. Project Euler 88:Product-sum numbers 积和数

    Product-sum numbers A natural number, N, that can be written as the sum and product of a given set o ...

  7. lintcode :二叉树的最大深度

    题目: 二叉树的最大深度 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的距离. 样例 给出一棵如下的二叉树: 1 / \ 2 3 / \ 4 5 这个二叉树的最大深度为3. 解 ...

  8. Unity UGUI —— 无限循环List(转载)

    using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; ...

  9. cv论文(SPARSE REPRESENTATION相关)

    上个博文我讲了一些CNN相关的论文,比较浅显都是入门知识,这节课来总结一些稀疏表示方面的文章.至于上个博文说到的要讲的sparse coding的知识,我将会放在Deep Learning的专题里面讲 ...

  10. 2014--9=17 软工二班 MyEclipse blue==2

    关于Java中的getInetAddress方法 联网的话是一个分配的地址,不联网的话是本地localhost package cn.rwkj.test; import java.io.IOExcep ...