首页 > TAG信息列表 > Longge

[SDOI2012] Longge 的问题

题意 解析 首先设 g c d ( i , n )

[SDOi2012]Longge的问题

嘟嘟嘟 . \[\begin{align*} ans &= \sum_{i = 1} ^ {n} (i, n) \\ &= \sum _ {d | n} ^ {n} \sum _ {(i, n) = d} ^ {n} d \\ &= \sum _ {d | n} ^ {n} \sum _ {(i, \frac{n}{d}) = 1} ^ {\frac{n}{d}} d \\ &= \sum _ {d | n} ^ {n} d * \

poj2480 Longge‘s problem

Label 欧拉函数 Description 给定多个正整数 n ( 1 < n < 2

Longge's problem POJ - 2480

原题链接 数论的时间复杂度我真的越来越懵逼.....找个时间再琢磨一下 这道题枚举一定超时.将n分解质因数后也没找到什么规律.因此只能从gcd返回值入手.在int范围内约数最多是1536个.因此是可以枚举约数的 看了大佬的思路:       假设当前数字为i,设gcd(i,n)==k.那么为了简化计算

C - Longge's problem

POJ - 2480 求\(\sum_{i=1}^{n}\gcd(i,n)~(1\leq n\leq 10^9)\) 显然有 \[\sum_{i=1}^{n}\gcd(i,n)=\sum_{d|n}d\varphi(\frac nd) \](考虑 \(\varphi\) 的意义) 然后直接做随便做。 Code #include<iostream> #include<cstdio> using namespace std; long long get

[luogu2303]Longge的问题

1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 ll n,ans; 5 ll phi(ll n){ 6 ll ans=n; 7 for(ll i=2;i*i<=n;i++){ 8 if (n%i==0)ans=ans/i*(i-1); 9 while (n%i==0)n/=i;10 }11 if (n>1)ans=an

Longge's problem

Longge's problem 求\(\sum_{i=1}^ngcd(i,n)\),\(n< 2^{31}\)。 解 理解1: 注意式子的实际意义,显然答案只可能在n的约数中,而现在问题变成了每个约数出现了几次,而一个约数d要出现的次数,自然需要这个数有约数d,其他的约数与之互斥,于是考虑欧拉函数,故我们有 \[ans=\sum_{d|n}\varphi(n/

[SDOi2012]Longge的问题

这道题是数论题,所以需要一些变形。 考虑求所有$\gcd$的和,我们采用分组求解,也就是根据$i$和$N$的$\gcd$的值进行分组。 $$\begin{array}{ll}&\sum_{i=1}^N\gcd(i,N) \\ = &\sum_{d|n}d\sum_{i=1}^N[\gcd(i,N)=d]\\=&\sum_{d|n}d\sum_{i=1}^{\frac nd}[\gcd(i,\frac Nd)=1]\\=&\sum_{

题解报告:poj 2480 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, N) 1<=i <=N.