题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<algorithm> #include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; <<)+; ll n; int main() {…
Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i, N) 1<=i <=N. …
传送门 Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7327   Accepted: 2416 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms.…
题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因如下:1到n中有m个数字和n拥有公共的最大因子p,那么就需要把m*p加入答案中.问题是如何计算m的个数.因为假设某个数i与n的最大公约数为p,那么gcd(i,n) = p,可以得到gcd(i/p,n/p)=1.也就是说,有多少个i,就有多少个i/p与n/p互质.那么显然m即为n/p的欧拉函数φ(n/p). 知…
/** 大意: 计算f(n) = ∑ gcd(i, N) 1<=i <=N. 思路: gcd(i,x*y) = gcd(i,x) * gcd(i, y ) 所以gcd 为积性函数 又因为积性函数的和函数 也是积性函数(具体数学,了解即可) f(n) = f(p1^a1 * p2^a2 * p3^a3*......* pn^an ) = f(p1^a1) * f(p2^a2) * f(p3* a3) ...... 现在我们先单独考虑一个 f(p1^a1) f(p^k)=1*φ(p^k)+ p*φ…
题目: 给一个n,n的网格,点可以遮挡视线,问从0,0看能看到多少点 题解: 根据对称性,我们可以把网格按y=x为对称轴划分成两半,求一半的就可以了,可以想到的是应该每种斜率只能看到一个点 因为斜率表达式k=y/x,所以直线上的点都满足这个关系,那么显然当gcd(x,y)==1的时候这个点是直线上的第一个点,其他点的坐标一定是这个点的若干倍 所以问题转化成求gcd(x,y)==1的点对个数,即∑phi[i](1<=i<=n) 欧拉函数即可 #include<cstdio> usin…
前言:还算比较简单的数学题,我这种数学蒟蒻也会做QAQ. --------------- 题意:求$\sum\limits_{i=1}^n gcd(i,n)$的值. 设$gcd(i,n)=d$,即$d$为$i$和$n$的因数,那么有$gcd(i/d,n/d)=1$.假设我们求出了$x$个满足条件的$i$,那么总的结果就是$x*d$.我们因此可以枚举$n$的因数,累加即可.注意判断$n$是不是完全平方数. 问题来了:怎么求满足$gcd(i/d,n/d)=1$的$i$的个数?欧拉函数啊!我们可以$\…
Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6383   Accepted: 2043 Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now…
Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i,…
题意:定义 Fn 序列表示一串 <1 的分数,分数为最简分数,且分母 ≤n .问该序列的个数.(2≤N≤10^6) 解法:先暴力找规律(代码见屏蔽处),发现 Fn 序列的个数就是 Φ(1)~Φ(n) 的和.于是用欧拉筛预处理就好了. 注意--求前缀和要用 long long 的类型. 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<iostream> 5 usi…