HDU Integer's Power(容斥原理)】的更多相关文章

题意 求[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…
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…
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多少? 要求每个数字不能有前导0,即每个字符串首位字符不能赋0 分析: 对于每个字符,将每个字符串按位相加,得到这个字符的一个每位上的数量的数组 将其看成一个大数,满26进位,然后排序,从高到低赋值,注意考虑0 */ #include <bits/stdc++.h> using namespace…
找出(l,r)内的所有的指数最大的次方和 因为一个数可能可以看成a^b和c^d,所以我需要去重,从后往前枚举幂数,然后找可以整除的部分,把低次幂的数去掉. 然后开n方的部分,先用pow()函数找到最接近答案的数,但是会丢失精度,然后在这个数的附近寻找最接近答案的整数,用快速幂在乘n次幂回去,看最接近原本数的是哪一个. #include<map> #include<set> #include<ctime> #include<cmath> #include<…
Eddy's爱好 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2204 Description Ignatius 喜欢收集蝴蝶标本和邮票,但是Eddy的爱好很特别,他对数字比较感兴趣,他曾经一度沉迷于素数,而现在他对于一些新的特殊数比较有兴趣. 这些特殊数是这样的:这些数都能表示成M^K,M和K是正整数且K>1. 正当他再度沉迷的…
Number Sequence Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Given a number sequence b1,b2…bn. Please count how many number sequences a1,a2,...,an satisfy the condition that a1*a2*...*an=b1*…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5213 Lucky Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 763    Accepted Submission(s): 249 Problem Description WLD is always very lucky.His secret…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2668    Accepted Submission(s): 562 Problem Description Sample Input 1 a 2 aa bb 3 a ba abc Sample Output Case #1: 25 Case #2: 132…
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/article/details/5787722 题意 a,b,c,d,k五个数,a与c可看做恒为1,求在a到b中选一个数x,c到d中选一个数y,使得gcd(x,y)等于k,求x和y有多少对. 首先可以想到选取的必是k的倍数,假设是x和y倍,则x和y一定是互质的在,那么就变成了求1到b/k和1到d/k的之…
Coprime Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 849    Accepted Submission(s): 232 Problem Description Please write a program to calculate the k-th positive integer that is coprime with…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1411    Accepted Submission(s): 239 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters.…
题意: 给一个数的序列,询问一些区间,问区间内与区间其他所有的数都互质的数有多少个. 解法: 直接搞有点难, 所谓正难则反,我们求区间内与其他随便某个数不互质的数有多少个,然后区间长度减去它就是答案了. 那么怎么求区间内与区间其他某个数不互质的数的个数(记为cnt)呢? 我们用L[i],R[i]表示在整个序列中左边与 i 最近的与 i 不互质的数的位置,R[i]表示右边的,L[i],R[i]我们可以正反扫一遍顺便分解因子,用个pos[]记录很方便地求出.那么区间内的cnt为L[i]或R[i]在区…
题目链接 题意 : 从[a,b]中找一个x,[c,d]中找一个y,要求GCD(x,y)= k.求满足这样条件的(x,y)的对数.(3,5)和(5,3)视为一组样例 . 思路 :要求满足GCD(x,y)=k的对数,则将b/k,d/k,然后求GCD(x,y)=1的对数即可.假设b/k >= d/k ;对于1到b/k中的某个数s,如果s<=d/k,则因为会有(x,y)和(y,x)这种会重复的情况,所以这时候的对数就是比s小的与s互质的数的个数,即s的欧拉函数.至于重复的情况是指:在d/k中可能有大于…
读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector>…
看懂题目,很容易想到容斥原理. 刚开始我用的是二进制表示法实现容斥原理,但是一直超时.后来改为dfs就过了…… 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll __int64 #defin…
题意:……应该不用我说了,看起来就很容斥原理,很中国剩余定理…… 方法:因为题目中的n最大是15,使用状态压缩可以将所有的组合都举出来,然后再拆开成数组,进行中国剩余定理的运算,中国剩余定理能够求出同时满足余膜条件的最小整数x,x在(1,M)之间由唯一值,M是各个除数的乘积,所有符合条件的解为ans = x+k*M,可以知道在[1,R]这个区间内,有(M+R-x)/ M个k符合条件,然后在运算中为了防止溢出,所以使用了带膜乘法,就是将乘数转化为二进制,通过位移运算符,在中间过程中不断的取膜(看代…
A - Character Encoding HDU - 6397 思路 : 隔板法就是在n个元素间的(n-1)个空中插入k-1个板,可以把n个元素分成k组的方法 普通隔板法 求方程 x+y+z=10的正整数解的个数. 添元素隔板法 求方程 x+y+z=10的非负整数解的个数. 那么 增加 3 即转化为 了普通隔板法 但是这个题呢 还有 < N 的限制 ,那么就需要去除掉  ,分出的块中 有 > = n 的情况 . 就会 有 一块 出现 > =n ,两块 > =n 等等.. 具体…
Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) point. He wonders how ma…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5514 [题目大意] m个石子围成一圈,标号为0~m-1,现在有n只青蛙,每只每次跳a[i]个石子, 问能被青蛙跳到的石子一共有几个 [题解] 我们发现k*gcd(m,a[i])的位置均可以被跳到,那么我们首先筛出m的约数, 判断其是否被覆盖到,不考虑重复的情况下, 每个被覆盖到的约数的贡献为x*((m-1)/x)*((m-1)/x+1)/2, 但是约数的倍数也为约数的情况被重复计算,因此我们按约…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3555    Accepted Submission(s): 844 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. H…
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two differen…
Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 6703    Accepted Submission(s): 1680 Problem Description Talented Mr.Tang has n strings consisting of only lower case cha…
Description There are n people standing in a line. Each of them has a unique id number. Now the Ragnarok is coming. We should choose 3 people to defend the evil. As a group, the 3 people should be able to communicate. They are able to communicate if…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1047 题目意思:就是求大整数加法.有多个案例,每个案例之间要输出一个空格. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; + ; char t[maxn]; int s[maxn], ans[maxn]; int m…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3663 [算法] 先建图,然后用Dancing Links求解精确覆盖,即可 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 500000 int i,j,k,l,m,cnt,N,M,D,u,v; ][]; struct Time { int s,e; } ans[],a[]; struct info { int l,…
Time limit 1000 ms Memory limit 65536 kB OS Windows 中文题意 给一个数n,设将n质因数分解后可以得到 \[n=\prod_{i=1}^{\omega(n)} a_i^{p_i}\] 其中\(\omega(n)\)意思是n的不同质因子个数,\(a_i\)是n的质因子. 要求输出最小的\(p_i\). 题解 看完题解感觉很妙啊-- Let's first factorize \(N\) using prime numbers not larger…
Talented Mr.Tang has nn strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two different characters should not…
GCD Array Time Limit: 11000/5500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 843    Accepted Submission(s): 205 Problem Description Teacher Mai finds that many problems about arithmetic function can be reduced to…
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]$的数值.由于数据一定不…