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. 一个简单例子:贫血模型or领域模型

    转:一个简单例子:贫血模型or领域模型 贫血模型 我们首先用贫血模型来实现.所谓贫血模型就是模型对象之间存在完整的关联(可能存在多余的关联),但是对象除了get和set方外外几乎就没有其它的方法,整个 ...

  2. Android Studio 的安装和配置篇(Windows篇)

    上一篇介绍完了Android Studio,这一篇就专门来讲讲怎么安装配置的吧. 其实好多人都卡到安装配置这一步,想当初我也是,万恶的XX防火墙,导致下载Android Studio 的gradle异 ...

  3. [Angularjs]angular ng-repeat与js特效加载先后导致的问题

    写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...

  4. apue第六章学习总结

    apue第六章学习总结 1.关于阴影文件与口令 在口令文件当中,常见的字段有(以root为例): root(用户名):x(加密口令):0(uid):0(gid):root(注释字段):/root(用户 ...

  5. 前端框架react研究

    摘要: 最近公司要做一个嵌套在app中的应用,考虑着用Facebook的react来开发view,所以就研究了下.下面是我在开发中遇到的坑,希望能给你帮助. 项目地址:https://github.c ...

  6. centos linux从无到有安装wordpress

    序:本博客从无到有搭建wordpress,包括从服务器和域名购买,会将步骤一步一步记录下来.如果你也是新手,那你有福了,因为我的系统是centos,对号入座啊. 目录 一.准备域名和服务器一.安装ph ...

  7. Todd's Matlab讲义第1讲:向量,函数和作图

    向量 Matlab 中最基本的对象是矩阵,向量是特殊的矩阵.行向量是\(1\times n\)矩阵,列向量是\(m\times 1\)矩阵.输入如下行向量: >> v=[0 1 2 3] ...

  8. thinkphp中limit方法

    limit方法也是模型类的连贯操作方法之一,主要用于指定查询和操作的数量,特别在分页查询的时候使用较多.ThinkPHP的limit方法可以兼容所有的数据库驱动类的. 用法 限制结果数量 例如获取满足 ...

  9. iPod怎么下载歌曲?用iTunes传文件功能!

    昨儿一小美女拿我的手机听歌,说她不知道iPod怎么下载歌曲,因为还在上学家里不肯给买智能机,怕会影响学业.她的iPod shuffle刚买没多久还不会往里传歌曲,让我帮看看怎么整,心想她应该是没装iT ...

  10. Truck History(prim & mst)

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19772   Accepted: 7633 De ...