找出(l,r)内的所有的指数最大的次方和 因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉. 然后开n方的部分,先用pow()函数找到最接近答案的数,但是会丢失精度,然后在这个数的附近寻找最接近答案的整数,用快速幂在乘n次幂回去,看最接近原本数的是哪一个. #include<map> #include<set> #include<ctime> #include<cmath> #include<…
Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 320864-bit integer IO format: %I64d      Java class name: Main   LMY and YY are number theory lovers. They like to find and solve some interesti…
Integer’s Power Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description LMY and YY are number theory lovers. They like to find and solve some interesting number theory problems together. One day, they b…
题意: 让你从区间[a,b]里面找一个数x,在区间[c,d]里面找一个数y.题目上已经设定a=b=1了.问你能找到多少对GCD(x,y)=k.x=5,y=7和y=5,x=7是同一对 题解: 弄了半天才知道我得容斥原理方法卡时间了,我那个复杂度太高了...卧槽了 老版本的这里可以看:HDU - 4135 容斥原理 下面说一下复杂度低的容斥原理的思想 这种方法的基本思想是:先不考虑重叠的情况,把包含于某内容中的所有对象的数目先计算出来,然后再把计数时重复计算的数目排斥出去,使得计算的结果既无遗漏又无…
题意: 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树 题解: 用(x,y)表示某棵树的位置,那么只要x与y互质,那么这棵树就能被看到.不互质的话说明前面已经有树挡住了这棵树 i是[1,m]中的任意一个数 我们可以for循环求在区间[1,n]内有多少数与i互质 求法就是容斥原理,具体见这里:HDU - 4135 容斥原理 代码: 1 /* 2 题意: 3 给你一个n*m的矩形,在1到m行,和1到n列上都有一棵树,问你站在(0,0)位置能看到多少棵树…
题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后再作差. 我们可以先求出num[i]代表[1,n]中最大指数为i的数有多少个. 然后枚举全部的i,然后让答案加上i*num[i]: 那么怎么求num[i]呢 我们可以求出[1,n]中指数为x的数有多少个作为num[x]的初步值.这个用n1/x就可以求出(不过要注意精度问题,及其恶心,看代码吧) 然后这个num…
1. 题目描述定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值.所求为区间$[a, b]$的数代入$f$的累加和,即\[\sum_{x=a}^{b} f(x)\]2. 基本思路因为数据很大, 因此不适合暴力枚举.但是对于给定的数$y$,我们可以求得$x^k \le y$.假设$x^k$均不相同,那么直接可解.因为存在$2^4 = 4^2$的情况,因此,这里其实是个容斥.即$c[i]$的数值应该减掉$c[k \cdot i]$的数值.由于数据一定不…
E - The Boss on Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4059 Description On Mars, there is a huge company called ACM (A huge Company on Mars), and it’s owned by a younger boss. Due…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7439    Accepted Submission(s): 2200 Problem Description   Now you get a number N, and a M-integers set, you shoul…
题目连接   http://acm.hdu.edu.cn/showproblem.php?pid=1796 处男容斥原理  纪念一下  TMD看了好久才明白DFS... 先贴代码后解释 #include<cstdio> #include<cstring> using namespace std; #define LL long long #define N 11 LL num[N],ans,n; int m,cnt; LL gcd(LL a,LL b) { int t; while…
Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2181    Accepted Submission(s): 920 Problem Description Given a positive integer N, your task is to calculate the sum of the positiv…
Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2577    Accepted Submission(s): 1102 Problem Description There are many trees forming a m * n grid, the grid starts from (1,1). Farm…
How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6630    Accepted Submission(s): 1913 Problem Description   Now you get a number N, and a M-integers set, you shoul…
状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示什么都不取得概率,p(x1)表示的是取x1的概率,最后要加一因为有又多拿了一次.整理一下就可以了. #include <cstdio> ; <<Maxn],p[Maxn]; int n; int main() { while (scanf("%d",&n)!…
容斥原理练习题,忘记处理gcd 和 lcm,wa了几发0.0. #include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; ll Num[]; ll gcd(ll a,ll b) { ? a : gcd(b,a%b); } int main() { ll N, M; while(scanf("%lld%lld",&am…
题意: 1 //一组数据 3 3 //数字为1-3,3次运算 2 2 3 //将2号位变成3 1 1 3 4 //计算1-3号位上与4互质的数的和 1 2 3 6 好题,需要重复练习 #include<stdio.h> #include<iostream> #include<map> #include<set> #include<algorithm> #include<string.h> #include<stdlib.h>…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5310    Accepted Submission(s): 1907 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y)…
Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4843    Accepted Submission(s): 1605 Problem Description There are m stones lying on a circle, and n frogs are jumping over them.The stones…
题意: 给你一个数n,找出来区间[1,n]内有多少书和n不互质 题解: 容斥原理 这一道题就让我真正了解容斥原理的实体部分 "容斥原理+枚举状态,碰到奇数加上(n-1)/lcm(a,b,c..) 碰到偶数减(n-1)/lcm(a,b,c...)" 这个是lcm(a,b,c,,,)可不是他们的乘积.. 注意了... 还有这道题输入会有0 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostr…
思路: 直接容斥 //By SiriusRen #include <cstdio> using namespace std; #define int long long ; int cases,a,b,n,tp,s[N]; int solve(int r){ ; ;i<(<<tp);i++){ ,t=; ;j<tp;j++) <<j))tmp*=s[j],t++; t=t&?:-; ans+=r/tmp*t; } return r-ans; } si…
题目大意: n件衣服,m条裤子,k双鞋子进行搭配 妈妈指明了哪些衣服和裤子不能搭配,哪些裤子和鞋子不能搭配,问最后有几种搭配方法 先假设都能搭配 n*m*k 每次遇到衣服和裤子不能搭的,就要减一次k,同时记录这个衣服和裤子出现的次数,避免以后重复减去的可以加回来 裤子和鞋子也是同样道理 #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; ] , pa[N][] ,…
题目大意: 输入样例个数T,每个样例输入三个数a,b,n,求[a,b]之间与n互素的个数 基本思路: 互斥,想想这个:AUBUC=A+B+C-A∩B-A∩C-B∩C+A∩B∩C fac存的是n的素因数que里存的是素因数的乘机以及符号,然后最后n/que得出的就是最后和n非互素的个数 代码如下: #include<cstdio> #include<cstdlib> #include<cstring> using namespace std; typedef long l…
Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multiplications: x2 = x × x, x3 = x2 × x, x4 = x3 × x, …, x31 = x30 × x. The operation of squaring can be appreciably shorten the sequence of multiplications.…
废话不多说,直接上题: SP7579 YOKOF - Power Calculus 题意翻译 (略过没有营养的题干) 题目大意: 给出正整数n,若只能使用乘法或除法,输出使x经过运算(自己乘或除自己,以及乘或除运算过程中产生的中间结果)变成x^n的最少步数 输入格式: 若干行数据,每行一个正整数n,数据以单独成行的0结束 输出格式: 若干行数据,对应每行输入的n所需的步数 题目描述 Starting with x and repeatedly multiplying by x, we can c…
[SinGuLaRiTy] Copyright (c) SinGuLaRiTy 2017.  All Rights Reserved. [CQBZOJ 2011] 计算系数 题目描述 给定一个多项式(ax + by)^k,请求出多项式展开后x^n y^m项的系数. 输入 共一行,包含 5 个整数,分别为a,b,k,n,m,每两个整数之间用一个空格隔开. 输出 输出共 1 行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007 取模后的结果. 样例数据 样例输入 样例输出 1 1 3…
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the…
D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 …
Description Starting with x and repeatedly multiplying by x, we can compute x31 with thirty multiplications: x2 = xxx,     x3 = x2xx,     x4 = x3xx,     ...  ,     x31 = x30xx. The operation of squaring can appreciably shorten the sequence of multipl…
题意翻译 题意:给出一个n个数组成的数列a,有t次询问,每次询问为一个[l,r]的区间,求区间内每种数字出现次数的平方×数字的值 的和. 输入:第一行2个正整数n,t. 接下来一行n个正整数,表示数列a1​~an的值. 接下来t行,每行两个正整数l,r,为一次询问. 输出:t行,分别为每次询问的答案. 数据范围:1≤n,t≤2∗105,1≤ai≤106,1≤l,r≤n 题目描述 An array of positive integers a1,a2,...,an a_{1},a_{2},...,…
题目链接:点击传送 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar…