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 ...
随机推荐
- virtualbox 不能为虚拟电脑打开一个新任务/VT-x features locked or unavailable in MSR.
确保了主机的BIOS中开启了Intel Virtual Technology,虚拟机配置中勾选了“启用VT-x/AMD-V”. 这是因为CPU不支持VT-X技术或者VT-X技术被锁定. 如果不打开虚拟 ...
- 深入理解Java中的继承
对于面向对象的程序设计而言,每一个程序员都应该去了解Java中的封装,继承和多态,那么我今天来说的主要是以继承为核心的主题. 一.关于对继承的理解. 继承是面向对象的三大特性之一,是java中实现代码 ...
- codeforces 258div2C Predict Outcome of the Game
题目链接:http://codeforces.com/contest/451/problem/C 解题报告:三个球队之间一共有n场比赛,现在已经进行了k场,不知道每个球队的胜场是多少,如三个球队的胜场 ...
- Encapsulation and Requiring Files
By encapsulating all the logic for an object, whether it’s a Dog or a User or an IceCreamShop, you a ...
- 关于mac安装rails报错clang: error: unknown argument
文章都是从我的个人博客上转载过来的,大家可以点击我的个人博客. www.iwangzheng.com mac上安装rails的时候报错, 安装rails的在终端执行了一句命令: $sudo gem i ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- HTML快速入门3
四.表格 (Table) 1. 表格的基本形式 表由 <table> 开始, </table> 结束,表的内容由 <tr>,<th> 和 <td& ...
- zb的生日
http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 ...
- datetime中strftime和strptime用法
from datetime import * format = "%Y-%m-%d %H:%M:%S" a=datetime.now() day=a.day b=a.replace ...
- ZOJ 2315
---恢复内容开始--- http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1315 这个题目比较难以看懂,我也是看网上的题目意思才 ...