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

题意:问1[,n]区间中,有多少个数,它的2,3,5,7,11,13的这几个因子数目之和为偶数

思路:预处理出所有的x,满足x只含有2,3,5,7,11,3这几个质因子,且数目为偶数。x的数目13000+;

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

    我用优先队列和map处理x;全用ll超时;有个地方会爆int,处理了下

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define pi 4*atan(1)
//#pragma comment(linker, "/STACK:102400000,102400000")
int p[]={,,,,,};
int num[],ji,ans;
struct is
{
int x;
int step;
bool operator <(const is a)const
{
return x>a.x;
}
};
priority_queue<is>q;
map<int,int>m;
int gcd(int x,int y)
{
return y==?x:gcd(y,x%y);
}
void init()
{
ji=;
is a;
a.x=;
m[]=;
a.step=;
q.push(a);
while(!q.empty())
{
is b=q.top();
if(b.x>1e9)
break;
q.pop();
if(b.step%==)
num[ji++]=b.x;
for(int i=;i<;i++)
{
is c;
ll gg=(ll)b.x*p[i];
if(gg>1e9)break;
c.step=b.step+;
c.x=(int)gg;
if(c.x<=1e9&&m[c.x]==)
q.push(c),m[c.x]=;
}
}
}
void dfs(int lcm,int pos,int step,int x)
{
if(lcm>x)
return;
if(pos==)
{
if(step==)
return;
if(step&)
ans+=x/lcm;
else
ans-=x/lcm;
return;
}
dfs(lcm,pos+,step,x);
dfs(lcm/gcd(p[pos],lcm)*p[pos],pos+,step+,x);
}
int main()
{
int x,y,z,i,t;
init();
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&x);
int Ans=;
for(i=;i<ji&&num[i]<=x;i++)
{
ans=;
dfs(,,,x/num[i]);
Ans+=(x/num[i]-ans);
}
printf("%d\n",Ans);
}
return ;
}

xtu 1242 Yada Number 容斥原理的更多相关文章

  1. xtu 1242 Yada Number 打表

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

  2. XTU 1242 Yada Number 容斥

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

  3. ZOJ 3233 Lucky Number --容斥原理

    这题被出题人给活活坑了,题目居然理解错了..哎,不想多说. 题意:给两组数,A组为幸运基数,B组为不幸运的基数,问在[low,high]区间内有多少个数:至少被A组中一个数整除,并且不被B中任意一个数 ...

  4. HDU 4390 Number Sequence 容斥原理

    Number Sequence Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. HDU 4390 Number Sequence (容斥原理+组合计数)

    HDU 4390 题意: 大概就是这样.不翻译了: Given a number sequence b1,b2-bn. Please count how many number sequences a ...

  6. [CF245H] Queries for Number of Palindromes (容斥原理dp计数)

    题目链接:http://codeforces.com/problemset/problem/245/H 题目大意:给你一个字符串s,对于每次查询,输入为一个数对(i,j),输出s[i..j]之间回文串 ...

  7. XTU OJ 1210 Happy Number (暴力+打表)

    Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...

  8. xtu summer individual 6 B - Number Busters

    Number Busters Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  9. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

随机推荐

  1. git add -A和git add . 的区别

    git add -A和 git add . git add -u在功能上看似很相近,但还是有所差别. git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容 ...

  2. Dij二级最短路

    hdu1245 Saving James Bond Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  3. maven修改本地仓库地址配置文件

    本地仓库是远程仓库的一个缓冲和子集,当你构建Maven项目的时候,首先会从本地仓库查找资源,如果没有,那么Maven会从远程仓库下载到你本地仓库.这样在你下次使用的时候就不需要从远程下载了.如果你所需 ...

  4. 170516、ActiveMQ 的安装与使用(单节点)

    ActiveMQ 的安装与使用(单节点)IP: 192.168.4.101环 境: CentOS 6.6 . JDK71. 安装 JDK 并配置环境变量(略)JAVA_HOME=/usr/local/ ...

  5. 2.06StuModify.aspx(修改姓名,性别,所在班级)

    meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title ...

  6. Redis讲解

    buffer  缓冲  用于写 cache  缓存  用于读 redis 支持持久化 安装redis yum -y install redis 配置文件/etc/redis.conf 是否在后台运行 ...

  7. codeforces#516 Div2---ABCD

    A---Make a triangle! http://codeforces.com/contest/1064/problem/A 题意: 给定三个整数表示三角形的边.每次给边长可以加一,问至少要加多 ...

  8. 解决Android版Firefox字体显示过大的问题

    在用Android版Firefox查看博客园首页发现中间区域的字体显示非常大,开始以为是首页css对移动版浏览器支持不好. 后来发现原来这是Firefox for Android的知名bug: Tha ...

  9. JS原生ajax

    原文链接:http://caibaojian.com/ajax-jsonp.html 一.JS原生ajax ajax:一种请求数据的方式,不需要刷新整个页面: ajax的技术核心是 XMLHttpRe ...

  10. 如何通过iframe调用其他页面的内容

    我们在建站的时候经常会在页面出现同样的内容,比如公司简介之类的,这些东西很长,会减低网页的原创程度,相似度太高,对SE不是很友好.这时我们可以考虑把这部分内容写成一个单独的简单页面,然后通过ifram ...