http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/acm_cxlove/article/details/7434864 1.求逆元   p=1e9+7是素数.所以由 a^(p-1)%p同余于1 可得a%p的逆元为a^(p-2) 2.segma(i^k)都能够通过推导得到求和公式 详见http://blog.csdn.net/acm_cxlove/ar…
传送门 The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2462    Accepted Submission(s): 760 Problem Description On Mars, there is a huge company called ACM (A huge Company on Mars)…
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1528    Accepted Submission(s): 452 Problem Description On Mars, there is a huge company called ACM (A huge Company on Mars), and…
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…
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #define LL long long using namespace std; ; ; LL Factor[],cnt,n,m,tot,Rev,Kase,Prime[Maxn]; bool vis[Maxn]; inline LL Quick_Pow(LL x,LL y) { LL Ret=; whi…
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以.他生平最恨情人节,无论是214还是77.他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 77=7*11 终于,他发现原来这一切归根究竟都是由于和7有关!所以,他如今甚至讨厌一切和7有关的数. 什么样的数和7有关呢? 假设一个整数符合以下3个条件之中的一个.那么我…
T1:数论+高精(水~) 根据题意可知,从除的数越大越好(在0~9中) 所以我们只要用到高精除然后再模拟一下就可以了 //MARK:但是要注意0-9这个特殊值需要特判,因为题目要求输出的数至少是两位数,所以0-9的数输出的时候应该在前面加上1.如果1的时候应该输出11,而不是1: T2:宽搜+深搜 典型的搜索题 因为有点忘了dfs所以还是学习了一下 其实之前一直以为bfs和dfs没有什么本质上的区别吧(除了时间复杂上的差异),学了强连通分量,以及这道题之后还是发现有很大不同的 说说这道题吧,bf…
p次方求和 Time Limit:1000MS  Memory Limit:65536K Total Submit:196 Accepted:46 Description 一个很简单的问题,求1^p+2^p+3^p+--+n^p的和. Input 第一行单独一个数字t表示测试数据组数.接下来会有t行数字,每行包括两个数字n,p,  输入保证0< n< =1000,0< =p< =1000. Output 输出1^p+2^p+3^p+--+n^p对10003取余的结果,每个结果单独占…
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD. \[ x=(p_1^{i_1})*(p_2^{i_2})*(p_3^{i_3})\dots \] \[ y=(p_1^{j_1})*(p_2^{j_2})*(p_3^{j_3})\dots \] \[ z=(p_1^{k_1})*(p_2^{k_2})*(p_3^{k_3})\dots \] \…
http://acm.hdu.edu.cn/showproblem.php?pid=4059 题意:给出一个n,求1~n里面与n互质的数的四次方的和是多少. 思路:不知道1~n的每个数的四次方的求和公式.看的是这篇:http://blog.csdn.net/acm_cxlove/article/details/7434864. 求和公式:(1^4+2^4+……+n^4)=(n*(n+1)*(2n+1)*(3*n*n+3*n-1))/30; 然后先求出1~n的每个数的四次方的求和,然后再减去n的因…
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2494    Accepted Submission(s): 775 Problem Description On Mars, there is a huge company called ACM (A huge Company on Mars), an…
The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若自己手动推公式的话,还是需要一定的数学基础. 总的思路:先求出sum1=(1^4)+(2^4)+...(n^4),再求出sum2=(1~n中与n不互质的数的四次方的和),answer=sum1-sum2. 如何求sum1呢? 有两种方法: 1.数列差分.由于A={Sn}={a1^4+a2^4+...an^4}…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 43847    Accepted Submission(s): 16487 Problem Description Given a positive integer N, you should output the most right digit of…
http://acm.hdu.edu.cn/showproblem.php?pid=4059 定义S = 1^4 + 2^4 + 3^4+.....+n^4.如今减去与n互质的数的4次方.问共降低了多少. 容斥原理.能够先把与n不互质的数的4次方求出来.那就先对n进行质因子分解,对质因子的组合运用容斥原理.质因子个数为奇数就加,偶数就减.事实上与求[1,n]内与n互质的数的个数类似,该题重点是计算,防止乘法溢出. 对于求解1^4 + 2^4 + 3^4+.....+n^4,能够先类比1^2+2^…
Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4904    Accepted Submission(s): 1631 Problem Description There are m stones lying on a circle, and n frogs are jumping over them.The stones…
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Special Judge Problem Description   In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people i…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y',x') = 1,同时lcm(x',y',x') = G/L. 特判,当G%L != 0 时,无解. 然后素数分解G/L,假设G/L = p1^t1 * p2^t2 *````* pn^tn. 满足上面条件的x,y,z一定为这样的形式. x' = p1^i1 * p2^i2 *```* pn^in.…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:在[a,b]中的x,在[c,d]中的y,求x与y的最大公约数为k的组合有多少.(a=1, a <= b <= 100000, c=1, c <= d <= 100000, 0 <= k <= 100000) 思路:由于x与y的最大公约数为k,所以xx=x/k与yy=y/k一定互质.要从a/k和b/k之中选择互质的数,枚举1~b/k,当选择的yy小于等于a/k时,能够…
Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees with coordinates (x1,y1), (x2,y2), and (x3,y3). Now Taotao is planning to plant a new one, but he is not willing to take these trees too close. He bel…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2204 解题报告:输入一个n让你求出[1,n]范围内有多少个数可以表示成形如m^k的样子. 不详细说了,自己一开始也忽略了三个素数的乘积的乘方的情况. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using names…
题目的大意就是求等差数列对应的Fibonacci数值的和,容易知道Fibonacci对应的矩阵为[1,1,1,0],因为题目中f[0]=0,f[1]=1,所以推出最后结果f[n]=(A^n-1).a,所以 f(g(i))= f(k*i+b)= (A^(k*i+b-1)).a,i从 0取到 n-1,取出公因式 A^(b-1)(因为矩阵满足分配率),然后所求结果可化为 A^(b-1) * (A^0 + A^k + A^2k +....+ A^(n-1)k),化到这里后难点就是求和了,一开始我尝试暴力…
引理: (Abel分部求和法) $$\sum_{k=1}^{n}a_{k}b_{k}=A_{n}b_{n}+\sum_{k=1}^{n-1}A_{k}(b_{k}-b_{k+1})$$其中$A_{k}=a_{1}+a_{2}+\cdots+a_{n}$. 结论 1: $$\sum_{k=1}^{n}k=\frac{k(k+1)}{2}$$结论 2:$$\sum_{k=1}^{n}k^{2}=\frac{n(n+1)(2n+1)}{6}$$证明: 由分部求和公式得\begin{align*}\su…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 889    Accepted Submission(s): 207 Problem Description "今有物不知其数,三三数之有二,五五数之有三,七七数之有…
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 92235 Accepted Submission(s): 38868 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这…
http://acm.hdu.edu.cn/showproblem.php?pid=5086 求一段数列里面所有连续和的和,卡精度 规律很明显,数列里面每个数都被加了i*(n+1-i)次 注意下精度即可 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include…
http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; 构造ci, k=min(j | i<j≤n,aj%ai=0), ci=ak; 求所有bi∗ci的和 f[x]表示能整除x的最近的下标,边构造边更新f数组,复杂度约为O(N*sqrt(A[I])) = O(10^7),可以接受,然后把所有b*c加起来即可 另外,我写的程序里面c[i]指的是上面说的b[i…
题意:定义如果一个数能表示为M^k,那么这个数是好数,问你1~n有几个好数. 思路:如果k是合数,显然会有重复,比如a^(b*c) == (a^b)^c,那么我们打个素数表,指数只枚举素数,2^60 > 1e18,所以打60以内素数就够了.但是显然指数为素数依然会有重复的,比如(a^b)^c == (a^c)^b,这里就要用到容斥了.我们如果用一个数组a[i]表示指数为第i个素数的数的个数,那么最终答案应该是,加上一个的,减去两个的,加上三个的(因为2 * 3 * 5 * 7 > 60,最多只…
Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1430    Accepted Submission(s): 392 Problem Description Given a positive integer n, your task is to find a positive integer m, w…
题目链接 题意:问从A到B中与N互素的个数. 题解: 利用容斥原理:先求出与n互为素数的个数. 可以先将 n 进行素因子分解,然后用区间 x 除以 素因子,就得到了与 n 的 约数是那个素因子的个数,然后每次这样求一遍,但是发现有重 复的:举个例子 [1,10] 区间中与 6 互素的个数,应该是 10−(10/2+10/3)+(10/6) 然后利用二进制枚举子集个数,奇数加偶数减. 具体看代码: #include <stdio.h> #include <cstring> #incl…
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5064    Accepted Submission(s): 1818 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)…