HDU - 2824 题意: 求[a,b]间的欧拉函数和.这道题卡内存,只能开一个数组. 思路: ϕ(n) = n * (p-1)/p * ... 可利用线性筛法求出所有ϕ(n) . #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <iomanip> #include <cstdlib> #include…
题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质的数的数目. 例如:φ(8)=4,因为1,3,5,7均和8互质. 性质:1.若p是质数,φ(p)= p-1. 2.若n是质数p的k次幂,φ(n)=(p-1)*p^(k-1).因为除了p的倍数都与n互质 3.欧拉函数是积性函数,若m,n互质,φ(mn)= φ(m)φ(n). 根据这3条性质我们就可以推…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are sm…
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004-欧拉函数水题 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typede…
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 166 Accepted Submission(s): 96   Problem Description The Euler function phi is an important kind of function in number theory…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2986    Accepted Submission(s): 1221 Problem Description The Euler function phi is an important kind of function in number theo…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5597 题意: http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=658&pid=1003 题解: f0(1)=2;  f0(2)=3;  f0(3)=4; f1(1)=3;  f1(2)=4;  f1(3)=5; f2(1)=4;  ...... 所以归纳出:fn(x)=n+x+1;  orz 然后求euler(…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5028    Accepted Submission(s): 2123 Problem Description The Euler function phi is an important kind of function in number theo…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4507    Accepted Submission(s): 1872     Problem Description The Euler function phi is an important kind of function in number…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4483 题意:给出一个(n+1)*(n+1)的格子.在这个格子中存在多少个三角形? 思路:反着想,所有情况减去不是三角形的.下面计算不是三角形的. (1)我们用C(n,m)表示组合数.考虑共线,一共有C((n+1)*(n+1),3)种情况.然后,要减去共线的情况.首先,三个点在同一行或者同一列,这种情况有2*(n+1)*C(n+1,3):最后就是斜着共线的情况: (2)对于斜着共线的情况,我们可以枚举…
题目链接 猜了一个结论,题面跟欧拉函数有关系. import java.util.*; import java.math.*; import java.text.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int p[] = new int[1001]; int prim[] = new int[100…
题目链接 题意 : 从[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中可能有大于…
题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eular(n)*n/2),得到的就是最终结果,所以也是模板题一道. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h&g…
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…
题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, b/k] $ 内 \(gcd(x, y) = 1\) 的(x, y)的对数. 假设a < b, 那么[1, a/k]这部分可以用欧拉函数算. 设 \(i\in (a/k, b/k]\), (a/k, b/k]这部分可以用容斥算, 用a/k减去[1, a/k]里面和i不互质的数的个数. 具体看代码.…
找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来.   Input 第一行是测试数据的组…
装载自:http://www.cnblogs.com/183zyz/archive/2012/05/11/2495401.html 题目让求一个函数调用了多少次.公式比较好推.f[n] = f[n-1]*f[n-2].然后a和b系数都是呈斐波那契规律增长的.需要先保存下来指数.但是太大了.在这里不能用小费马定理.要用降幂公式取模.(A^x)%C=A^(x%phi(C)+phi(C))%C(x>=phi(C)) Phi[C]表示不大于C的数中与C互质的数的个数,可以用欧拉函数来求. 矩阵快速幂也不…
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3702 Accepted Submission(s): 1640 Problem Description Do you have spent some time to think and try to solve those unsolved problem after o…
题目链接:https://cn.vjudge.net/contest/270608#problem/B 题目大意:题目中说,就是对欧拉函数的重新定义的一种函数的求和. 证明方法: AC代码: #include<iostream> #include<stack> #include<cstring> #include<iomanip> #include<cmath> #include<queue> #include<algorith…
https://blog.csdn.net/Lytning/article/details/24432651    记牢通式 =x((p1-1)/p1) * ((p2-1)/p2)....((pn-1)/pn) 求一个整数的欧拉函数: int eular(int n){ int res = n, x = n; for(int i = 2; i*i <= x; i++){ if(x % i == 0){ //是其中的一个质因数 res = res/i*(i-1);//保证为整数 且不会溢出 whi…
Declare: k=∑ m i=1 φ(i∗n) mod 1000000007 k=∑i=1mφ(i∗n) mod 1000000007 n n is a square-free number. φ φ is the Euler's totient function. find: ans=k k k k ... k      mod p ans=kkkk...k mod p There are infinite number of k k InputMultiple test cases(te…
一.欧拉函数 欧拉函数是小于x的整数中与x互质的数的个数,一般用φ(x)表示. 通式:   其中p1, p2……pn为x的所有质因数,x是不为0的整数. 比如x=12,拆成质因数为12=2*2*3, 12以内有1/2的数是2的倍数,那么有1-1/2的数不是2的倍数(1,3,5,7,9,11), 这6个数里又有1/3的数是3的倍数, 只剩下(1 - 1/2 - 1/3)的数既不是2的倍数,也不是3的倍数(1,5,7,11). 这样剩下的12*(1 - 1/2 - 1/3)=4,即4个数与12互质,…
如果打表的话会超内存,我想到了一种方法解决这个问题.题目给出的数据时3000000,我将三百万分成300个数据,将整万的数据存储下来,计算的时候,先计算x和y之间整万的数据,然后再计算零散数据. 想法很不错,但为啥就是通不过呢?而且看提交返回的时间来看,应该是卡在最后一两组数据上了. 我很疑惑. 代码中注释的部分是我之前的代码.最后这道题竟然是毫无美感的暴力过去了. #include<stdio.h> #include<string.h> #define N 3000005 int…
题目链接: GTW likes function Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Problem Description   Now you are given two definitions as follows. f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1) Note th…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5895 f(n)=f(n-2)+2*f(n-1) f(n)*f(n-1)=f(n-2)*f(n-1)+2*f(n-1)*f(n-1); 2*f(n-1)*f(n-1)=f(n)*f(n-1)-f(n-2)*f(n-1); 累加可得 g(n) = f(n)*f(n+1)/2   然后这个公式:A^x % m = A^(x%phi(m)+phi(m)) % m (x >= phi(m))   反正比赛没做…
题意: 定义函数\(f(n)\)为\(i \cdot j \not\equiv 0 \; (mod \; n)\)的数对\((i,j)\)的个数\((0 \leq i,j \leq n)\) \(g(n)=\sum_{d|n}f(d)\),求\(g(n) \; mod \; 2^{64}\),其中\(1 \leq n \leq 10^9\) 仰慕叉老师手推公式 分析: 计算\(f(n)\) \(f(n)\)不容易计算,但可以计算它的反面,也就是计算满足\(ij \equiv 0 \; (mod…
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…
找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6952    Accepted Submission(s): 3612 Problem Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数…
1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a,b)间的欧拉函数值的和. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio>…
<题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. 解题分析: 其实只要看懂题目就会…