HDU 3501 Calculation 2】的更多相关文章

Calculation 2 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is s…
Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1750    Accepted Submission(s): 727 Problem Description Given a positive integer N, your task is to calculate the sum of the positiv…
题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eular(n)*n/2),得到的就是最终结果,所以也是模板题一道. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h&g…
题目 题意:求小于n并且 和n不互质的数的总和. 思路:求小于n并且与n互质的数的和为:n*phi[n]/2 . 若a和n互质,n-a必定也和n互质(a<n).也就是说num必定为偶数.其中互质的数成对存在.其和为n. 公式证明: 反证法:如果存在K!=1使gcd(n,n-i)=k,那么(n-i)%k==0而n%k=0那么必须保证i%k=0k是n的因子,如果i%k=0那么gcd(n,i)=k,矛盾出现; 所以先求出1……n-1 的和, 再用这个和 减去 上面公式求出来的值. 欧拉函数phi(m)…
题目大意:求小于n的与n不互质的数的和. 题解:首先欧拉函数可以求出小于n的与n互质的数的个数,然后我们可以发现这样一个性质,当x与n互质时,n-x与n互质,那么所有小于n与n互质的数总是可以两两配对使其和为n,这也就是为什么当n大于2时欧拉函数都是偶数,知道这一点后,就可以计算出小于n与n互质的数的和了,那么不互质的和只要用总和来减就可以了. #include <cstdio> typedef long long LL; LL n,ans; LL Eular(LL n){ LL ret=1;…
[题目分析] 卷积太有趣了. 最终得出结论,互质数和为n*phi(n)/2即可. 计算(n*(n+1)/2-n-n*phi(n)/2)%md,用反正法即可证明. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #includ…
Description Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1. Input For each test case, ther…
http://acm.hdu.edu.cn/showproblem.php?pid=3501 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4548    Accepted Submission(s): 1878 Problem Description Given a positive integer N, your task is t…
https://vjudge.net/problem/HDU-3501 不会做啊...记一下做法 做法是计算小于n且与n互质的数的和:根据如果gcd(i,n)==1,那么gcd(n-i,n)==1,对这些数两两一组分组,使得每组的和为n 后面自己去想了一下,想出了一个奇怪的做法.. 化简出来小于n且与n互质的数的和是$\sum_{d|n}\mu(d)\sum_{j=1}^{{\lfloor}\frac{n-1}{d}{\rfloor}}(dj)$ 于是暴力枚举因子,暴力根号n求莫比乌斯函数,得到…
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1. InputFor each test case, there is a line c…
题面: 题解:欧拉函数的基础应用,再套个很 easy 的等差数列前 n 项和就成了. 啊,最近在补作业+准备月考+学数论,题就没怎么写,感觉菜得一匹>_< CSL加油加油~! 代码: #include<cstdio> #include<cmath> #define ll long long #define mod(a) ((a)>=MOD?(a)%MOD:(a)) using namespace std; ; ll N,sq,phi,n; int main(){…
Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2272    Accepted Submission(s): 536 Problem Description Assume that f(0) = 1 and 0^0=1. f(n) = (n%10)^f(n/10) for all n bigger than ze…
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…
公式:a^b%p=a^(b%phi(p)+phi(p))%p   b>=phi(p) #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<string> #include<vector> #define ll __int64 using namespace std; ll…
题目链接 分析: 要求的是小于$n$的和$n$不互质的数字之和...那么我们先求出和$n$互质的数字之和,然后减一减就好了... $\sum _{i=1}^{n} i[gcd(i,n)==1]=\left \lfloor \frac{n\phi(n)}{2} \right \rfloor$ 考虑$gcd(n,i)=1$,那么必然有$gcd(n,n-i)=1$,然后发现如果把$gcd(n,i)=1$和$gcd(n,n-i)=1$凑到一起会出现$n$,这样的有$\left \lfloor \frac…
欧拉函数 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) . 通式:φ(x)=x*(1-1/p1)(1-1/p2)(1-1/p3)*(1-1/p4)-..(1-1/pn),其中p1, p2--pn为x的所有质因数,x是不为0的整数.φ(1)=1(唯一和1互质的数就是1本身). 对于质数p,φ(p) = p - 1.注意φ(1)=1. 欧拉定理:对于互质的正整数a和n,有aφ(n) ≡ 1 mod n. 欧拉函数是积性函数--若m,n互质,φ(mn)=φ(m…
HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsum  贪心 HDU 1004 Let the Balloon Rise  字典树,map HDU 1005 Number Sequence  求数列循环节 HDU 1007 Quoit Design  最近点对 HDU 1008 Elevator  模拟 HDU 1010 Tempter of th…
8-15-小练 这次的题目......只觉得泪奔啊......T T A.HDU 1042   N! 因为0<=n<=1000,故一定要用数组或字符串[同样因为n<=1000故用数组就够了~~~]. 代码: #include <iostream> #include <cstdio> using namespace std; ]; int main() { int n,i,j; while(~scanf("%d",&n)) { || n=…
题目传送门 Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6114    Accepted Submission(s): 2499 Problem Description Given a positive integer N, your task is to calculate the sum of the…
素数筛 朴素算法 一般来说,可以用试除法判断某一个数是不是素数: bool isPrime(int n) { if(n < 2) return false; for(int i = 2; i < n; i++) if(n % i == 0) return false; return true; } 但其实我们只需要试除到根号n即可,因为对于任意的n,假设存在一个大于根号n的因数,那么肯定存在一个小于根号n的因数与之对应.那么有: bool isPrime(int n) { if(n <…
从费马小定理到欧拉定理 欧拉公式 再到欧拉函数.,. 小结一下欧拉函数吧 对正整数n,欧拉函数是小于n的正整数中与n互质的数的数目(φ(1)=1)----定义 欧拉函数的基本公式其中pi为x的素因子 .公式的推导根据欧拉公式(积性函数的性质)+算术基本定理+phi(p^k)=p^k-p^(k-1)(p为素数) 简单应用 1.hdu 2588 题意:给定N,M求gcd(i,N)>=M的i的个数(1<=i<=N,M<=N) 题解 :  对于每个i因为i<=N 所以g=gcd(N,…
题目链接.hdu 4965 Fast Matrix Calculation 题目大意:给定两个矩阵A,B,分别为N*K和K*N. 矩阵C = A*B 矩阵M=CN∗N 将矩阵M中的全部元素取模6,得到新矩阵M' 计算矩阵M'中全部元素的和 解题思路:由于矩阵C为N*N的矩阵,N最大为1000.就算用高速幂也超时,可是由于C = A*B, 所以CN∗N=ABAB-AB=AC′N∗N−1B,C' = B*A, 为K*K的矩阵,K最大为6.全然能够接受. #include <cstdio> #inc…
HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个仅仅有6x6.就能够用矩阵高速幂搞了 代码: #include <cstdio> #include <cstring> const int N = 1005; const int M = 10; int n, m; int A[N][M], B[M][N], C[M][M], CC[N…
题目链接:hdu 4965,题目大意:给你一个 n*k 的矩阵 A 和一个 k*n 的矩阵 B,定义矩阵 C= A*B,然后矩阵 M= C^(n*n),矩阵中一切元素皆 mod 6,最后求出 M 中所有元素的和.题意很明确了,便赶紧敲了个矩阵快速幂的模板(因为编程的基本功不够还是调试了很久),然后提交后TLE了,改了下细节,加了各种特技,比如输入优化什么的,还是TLE,没办法,只好搜题解,看了别人的题解后才知道原来 A*B 已经是 n*n 的矩阵了,所以(A*B)n*n 的快速幂里的每个乘法都是…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4726 题意:给出两个n位的数字,均无前缀0.重新排列两个数字中的各个数,重新排列后也无前缀0.得到的两个新数相加和最大.这里的相加是无进位的相加.输出结果.输出时不要输出前缀0. 思路:答案的第一位比较特殊,相加的两个数中不能有0.可以枚举这个答案中的第一个数字,查找是否存在两个数相加为这个数字.后面的道理一样,也是枚举. int a[2][10]; int n; char s[2][N]; int…
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 513 Accepted Submission(s): 142 Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia…
One day, Alice and Bob felt bored again, Bob knows Alice is a girl who loves math and is just learning something about matrix, so he decided to make a crazy problem for her. Bob has a six-faced dice which has numbers 0, 1, 2, 3, 4 and 5 on each face.…
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 83    Accepted Submission(s): 16 Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But K…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4965 题意 给出两个矩阵 一个A: n * k 一个B: k * n C = A * B M = (A * B) ^ (n * n) 然后将M中所有的元素对6取余后求和 思路 矩阵结合律.. M = (A * B) * (A * B) * (A * B) * (A * B) * (A * B) * (A * B) * (A * B) * (A * B) -- 其实也等价于 M = A * (B *…
感觉本题没有什么好解释的,已知公式,直接编程即可. 1.统计所有 科目的学分 得到总学分 2.统计所有 成绩对应的绩点*对应的学分即可(如果成绩==-1直接continue,不进行统计),得到总绩点. 3.如果总绩点<0 sorry -1,没有平均绩点 4. 总绩点/总学分 即可得到平均绩点 #include <stdio.h> int f(double x) { if(x>=90)return 4; else if(x>=80)return 3; else if(x>…