Yada Number

Problem Description:

Every positive integer can be expressed by multiplication of prime integers. Duoxida says an integer is a yada number if the total amount of 2,3,5,7,11,13 in its prime factors is even.

For instance, 18=2 * 3 * 3 is not a yada number since the sum of amount of 2, 3 is 3, an odd number; while 170 = 2 * 5 * 17 is a yada number since the sum of amount of 2, 5 is 2, a even number that satifies the definition of yada number.

Now, Duoxida wonders how many yada number are among all integers in [1,n].

Input

The first line contains a integer T(no more than 50) which indicating the number of test cases. In the following T lines containing a integer n. ()

Output

For each case, output the answer in one single line.

Sample Input

2
18
21

Sample Output

9
11












题意:

  给你一个n,问你1到n里面有多少个数满足 因子中是2,3,5,7,11,13的个数为偶数个

题解:

   预处理出所有的x,满足x只含有2,3,5,7,11,3这几个质因子,且数目为偶数。x的数目略大于10000

  注意加入0个的情况,即1.

对于一个数n,枚举所有的x,对于一个x,f(n/x)即求出[1,n/x]中不含有2,3,5,7,11,13作为因子的数有多少个,这个是经典的容斥问题。

 最后对所有的f(n/x)求和即可

#include<bits/stdc++.h>
using namespace std;
const int N = 3e6+, M = 1e6+, mod = 1e9+,inf = 1e9; typedef long long ll;
const ll maxn = 1e9;
int cnt = , ans,n;
ll b[N];
int a[] = {,,,,,};
ll gcd(ll a,ll b) {return b==?a:gcd(b,a%b);}
void dfs(ll x,int f,int num) {
if(num==) {
if(!f) b[cnt++] = x;
return ;
}
while(x<=maxn) {
dfs(x,f,num+);
x*=a[num];
f^=;
}
}
void init() {
dfs(,,);
sort(b,b+cnt);
} void inclu(int i,int num,ll tmp) {
if(tmp>n) return ;
if(i>=) {
if(num==) ans = ;
else {
if(num&) ans = ans+n/tmp;
else ans = ans-n/tmp;
}
return ;
}
inclu(i+,num,tmp);
inclu(i+,num+,tmp*a[i]/gcd(tmp,a[i]));
} void solve() {
int Ans = ;
scanf("%d",&n);
int tm = n;
for(int i=;i<cnt&&b[i]<=tm;i++) {
n = tm/b[i];
ans = ;
inclu(,,);
Ans+=(n - ans);
}
printf("%d\n",Ans);
}
int main() {
int T;
cnt = ;
init();
scanf("%d",&T);
while(T--) {
solve();
}
return ;
}

XTU 1242 Yada Number 容斥的更多相关文章

  1. xtu 1242 Yada Number 容斥原理

    Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime ...

  2. xtu 1242 Yada Number 打表

    Yada Number       Time Limit : 2000 MS   Memory Limit : 65536 KB   Yada Number Problem Description: ...

  3. CF1221G Graph And Number(容斥,搜索,FMT)

    至今觉得这场 edu 的 G 比 EF 都要简单-- 不知道为什么出题人要把 \(m=0\) 放进去,先特判掉. 要求至少一个 \(0\),至少一个 \(1\),至少一个 \(2\),容斥一波,变成总 ...

  4. 双元素非递增(容斥)--Number Of Permutations Educational Codeforces Round 71 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1207/problem/D n个元素,每个元素有a.b两个属性,问你n个元素的a序列和b序列有多少种排序方法使他们不同时非递减(不同时g ...

  5. cf#305 Mike and Foam(容斥)

    C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. UVa12633 Super Rooks on Chessboard(容斥 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...

  7. HDU How many integers can you find 容斥

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  9. HDU 5794 A Simple Chess (容斥+DP+Lucas)

    A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board ...

随机推荐

  1. Ueditor配置及在项目中的使用

    引言 上篇中简单介绍了Ueditor的两种定制方式,想了解的请戳这里:Ueditor的两种定制方式.在项目中,Ueditor该怎么使用更方便呢?很容易让人想到将ueditor放入用户控件页,可以拖到需 ...

  2. whereis命令

    whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度非 ...

  3. HDOJ 2389 Rain on your Parade

     HK.... Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K ...

  4. PHP5 Session 使用详解(一)

    http协议是WEB服务器与客户端(浏览器)相互通信的协议,它是一种无状态协议.所谓无 状态,指的是不会维护http请求数据,http请求是独立的,不持久的.而越来越复杂的WEB应用,需要保存一些用户 ...

  5. 淘宝(阿里百川)手机客户端开发日记第四篇 自定义ListView详解

    我们知道,如果采用官方的ListView,实现的功能在很多时候,并不能满足自己的业务需求,比如在设计到复杂的列表的时候,这一节,我们就开始动手自己实现自定义的ListView. 在上一节中,我们采用了 ...

  6. C# params关键字

    params数组的要点 C#开发语言中 params 是关键字,可以指定在参数数目可变处采用参数的方法参数.在函数的参数数目可变而执行的代码差异很小的时候很有用! class Program { st ...

  7. 图像特征提取:Sobel边缘检测

    前言 点和线是做图像分析时两个最重要的特征,而线条往往反映了物体的轮廓,对图像中边缘线的检测是图像分割与特征提取的基础.文章主要讨论两个实际工程中常用的边缘检测算法:Sobel边缘检测和Canny边缘 ...

  8. Linux netstat +awk 看攻击IP

     netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n<=2)++S[array[(1)]];else++S[a ...

  9. Linux下列格式化工具 - column

    [root@localhost ~]# mount/dev/sda2 on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type ...

  10. shell中常用的命令方法

    <1>Linux Shell 脚本中字符串的连接方法 [root@localhost company]# var1=/etc/[root@localhost company]# var3= ...