XTU 1242 Yada Number 容斥
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 容斥的更多相关文章
- xtu 1242 Yada Number 容斥原理
Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime ...
- xtu 1242 Yada Number 打表
Yada Number Time Limit : 2000 MS Memory Limit : 65536 KB Yada Number Problem Description: ...
- CF1221G Graph And Number(容斥,搜索,FMT)
至今觉得这场 edu 的 G 比 EF 都要简单-- 不知道为什么出题人要把 \(m=0\) 放进去,先特判掉. 要求至少一个 \(0\),至少一个 \(1\),至少一个 \(2\),容斥一波,变成总 ...
- 双元素非递增(容斥)--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 ...
- cf#305 Mike and Foam(容斥)
C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- UVa12633 Super Rooks on Chessboard(容斥 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...
- HDU How many integers can you find 容斥
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 1695 GCD 容斥
GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...
- 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 ...
随机推荐
- myBatis 实现用户表增删查改操作<方法2 加入接口>(最终版)
这2种方法的区别:1.添加接口 2.运用接口来实现 其他的都一样 添加接口 //接口的名字和xml的名字一样,这样xml中的namespace就不用改 public interface UserMap ...
- WPF 检测计算机网络连接情况
; ; ; ; [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(ou ...
- SQL 两种表复制语句
1.INSERT INTO SELECT语句 语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Tab ...
- [bug]The file ‘/xxx/xxx.aspx’ has not been pre-compiled, and cannot be requested
今天莫名奇妙的出现了这个问题,查找很多资料最后解决了. 发现编译的时候,少了一个dll,导致预编译失败. 参考资料 https://blogs.msdn.microsoft.com/asiatech/ ...
- tar 的一个记录
今天看到群里有人在问.用tar命令备份/etc/passwd 文件提示删除/的提示 这里我要说明下,tar的打包压缩 命令: tar -zcv -f /backup/passwd.tar.gz /et ...
- 移动web调式利器---Rosin研究
移动web调式利器---Rosin研究 阅读目录 关于Rosin Rosin在Fiddler中如何使用 回到顶部 一:关于Rosin Rosin是Fiddler的一个插件,它能接受页面中的JS的con ...
- Java转义符\\|
http://blog.csdn.net/stewen_001/article/details/22871737 看一段程序 String t = "a||b||c||d"; St ...
- Linux解压安装与卸载
linux tar.gz zip 解压缩 压缩命令 linux下安装软件主要有这么几种: 1.自动安装: yum install package 2.用二进制文件安装:rpm -ivh file.rp ...
- Android 遍历界面控件
//遍历界面上的控件 fubin.pan LinearLayout sLinerLayout = (LinearLayout)findViewById(R.id.layout_scr); for (i ...
- [Effective JavaScript 笔记]第44条:使用null原型以防止原型污染
第43条中讲到的就算是用了Object的直接实例,也无法完全避免,Object.prototype对象修改,造成的原型污染.防止原型污染最简单的方式之一就是不使用原型.在ES5之前,并没有标准的方式创 ...