HDU2841 (队列容斥)
Visible TreesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2213 Accepted Submission(s): 908
If two trees and Sherlock are in one line, Farmer Sherlock can only see the tree nearest to him.
1 1
2 3
5
#include<bits/stdc++.h>
using namespace std;
__int64 n;
__int64 a,b;
__int64 slove( __int64 m,__int64 gg)
{
__int64 que[1000];
__int64 a[1000];
memset(que,0,sizeof(que));
memset(a,0,sizeof(a));
__int64 sum=0;
__int64 t=0;
__int64 ss=0;
for(__int64 i=2;i*i<=m;i++)
{
if(m%i==0)
{
que[ss++]=i;
while(m%i==0)
m=m/i;
}
}
if(m>1)
que[ss++]=m;
a[t++]=-1;
for(__int64 i=0;i<ss;i++)
{
int k=t;
for(__int64 j=0;j<k;j++)
{
a[t++]=que[i]*a[j]*(-1);
}
}
for(__int64 i=1;i<t;i++)
sum=sum+gg/a[i];
return sum;
}
int main()
{
while(scanf("%I64d",&n)!=EOF)
{
for(__int64 i=1;i<=n;i++)
{
__int64 re=0;
scanf("%I64d %I64d",&a,&b);
for(__int64 j=1;j<=a;j++)
re+=slove(j,b);
printf("%I64d\n",a*b-re);
}
}
return 0;
}
HDU2841 (队列容斥)的更多相关文章
- 【XSY1580】Y队列 容斥
题目大意 给你\(n,r\),求第\(n\)个不能被表示为\(a^b(2\leq b\leq r)\)的数 \(n\leq 2\times {10}^{18},r\leq 62\) 题解 我们考虑二分 ...
- 【hdu4135】【hdu2841】【hdu1695】一类通过容斥定理求区间互质的方法
[HDU4135]Co-prime 题意 给出三个整数N,A,B.问在区间[A,B]内,与N互质的数的个数.其中N<=10^9,A,B<=10^15. 分析 容斥定理的模板题.可以通过容斥 ...
- hdu 5664 Lady CA and the graph(树的点分治+容斥)
题意: 给你一个有n个点的树,给定根,叫你找第k大的特殊链 .特殊的链的定义:u,v之间的路径,经过题给的根节点. 题解:(来自BC官方题解) 对于求第k大的问题,我们可以通过在外层套一个二分,将其转 ...
- HDU 4135 Co-prime (容斥+分解质因子)
<题目链接> 题目大意: 给定区间[A,B](1 <= A <= B <= 10 15)和N(1 <=N <= 10 9),求出该区间中与N互质的数的个数. ...
- HDU 4135 Co-prime 欧拉+容斥定理
Co-prime Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 15ecjtu校赛1006 (dfs容斥)
Problem Description 在平面上有一个n*n的网格,即有n条平行于x轴的直线和n条平行于y轴的直线,形 成了n*n个交点(a,b)(1<=a<=n,1<=b<= ...
- POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)
题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
随机推荐
- C for阶乘
#include <stdio.h> int main(int argc, char **argv) { //定义三个变量 x n s ,n s的初始值为1; int x; i ...
- Java学习 · 初识 IO流
IO流 1. 原理与概念 a) 流 i. 流动,流向 ii. 从一端移动到另一端 源头到目的地 iii. 抽象.动态概念,是一连 ...
- 解决jQuery不同版同时引用的冲突
今天研发的同事在开发一个新jQuery插件时,遇到一个揪心的问题.平台以前使用的 jQuery版本是1.2.6,偶,天啊!这是古代的版本啊! 由于很多功能基于老版本,不能删除啊,同志们都懂的! 于是我 ...
- python简单循环生成器
import time #循环生成器 def traversal_list(alist, i): while True: length = len(alist) i = i%(length) yiel ...
- python邮件服务-yagmail
下载安装 yagmail import yagmail #链接邮箱服务器 #此处的password是授权码 yag= yagmail.SMTP( user="843092012@qq.c ...
- Python3 Tkinter-Button
1.绑定事件处理函数 from tkinter import * def hello(): print('Hello!') root=Tk() button=Button(root,text='cli ...
- openstack如何整合vmare最佳方案
OpenStack中国社区编者按:通过多年的发展,VMWare在虚拟化市场处于领军地位,很多企业部署了VMWare虚拟化方案,随着OpenStack云计算平台的快速崛起,很多企业都面临一个问题:能否. ...
- SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)
Description You are given N circles and expected to calculate the area of the union of the circles ! ...
- codeforces 303C. Minimum Modular(数论+暴力+剪枝+贪心)
You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the ...
- HDU 1007 Quoit Design(计算几何の最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...