bzoj 2226 LCMSum 欧拉函数
2226: [Spoj 5971] LCMSum
Time Limit: 20 Sec Memory Limit: 259 MB
Submit: 1123 Solved: 492
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1
2
5
Sample Output
4
55
HINT
Constraints
1 <= T <= 300000
1 <= n <= 1000000
思路:时间复杂度T*sqrt(n);
小于n并且与n互质的数为phi(k)*k/2;
1的情况是特例;全部long long会超时。。。卡死我了
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
const int MAXN=;
int prime[MAXN],cnt;
bool vis[MAXN];
int phi[MAXN];
void Prime(int n)
{
phi[]=;
for(int i=;i<n;i++)
{
if(!vis[i])
{
prime[cnt++]=i;
phi[i]=i-;
}
for(int j=;j<cnt&&i*prime[j]<n;j++)
{
int k=i*prime[j];
vis[k]=;
if(i%prime[j]==)
{
phi[k]=phi[i]*prime[j];
break;
}
else
phi[k]=phi[i]*(prime[j]-);
}
}
}
ll phii(ll n)
{
return (ll)phi[n]*n/;
}
int main()
{
int x,y,z,i,t;
Prime();
scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
ll ans=;
ll gg=sqrt(x);
for(i=;i<=gg;i++)
{
if(x%i==)
ans+=phii(x/i),ans+=phii(i);
}
if(gg*gg==x)
ans-=phii(gg);
printf("%lld\n",(ans+)*x);
}
return ;
}
bzoj 2226 LCMSum 欧拉函数的更多相关文章
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- 【bzoj2226】[Spoj 5971] LCMSum 欧拉函数
题目描述 Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Leas ...
- BZOJ 2818 Gcd(欧拉函数+质数筛选)
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB Submit: 9108 Solved: 4066 [Submit][Status][Discu ...
- BZOJ2226:LCMSum(欧拉函数)
Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes t ...
- bzoj 2705 数学 欧拉函数
首先因为N很大,我们几乎不能筛任何东西 那么考虑设s(p)为 gcd(i,n)=p 的个数,显然p|n的时候才有意义 因为i与n的gcd肯定是n的因数,所以那么可得ans=Σ(p*s(p)) 那么对于 ...
- 【BZOJ2226】[Spoj 5971] LCMSum 莫比乌斯反演(欧拉函数?)
[BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n ...
- bzoj 2818 GCD 数论 欧拉函数
bzoj[2818]Gcd Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Samp ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- bzoj 2190 [SDOI2008]仪仗队(欧拉函数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2190 [题意] n*n的正方形,在(0,0)格点可以看到的格子数目. [思路] 预处理 ...
随机推荐
- ios 去除UITextField中的空格
NSString *qName =[userNameText.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNew ...
- 【Android】安卓中常用的图片加载方法
一.通过相机选图片: 布局文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- DFS判断正环
hdu1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 国外DNS服务器总结
国外12个免费的DNS DNS(即Domain Name System,域名系统),是因特网上作为域名和IP地址相互映射的一个分布式数据库,能够让用户更方便的访问互联网,而不用去记住能够被机器直接读取 ...
- 【ArcGIS for SivlerLight api(3)】基础图层增删改查
1.基础底图通常使用TiledLayer或者ArcGISDynamicLayer. 本质上都是在本地加载栅格图片.后台生成策略不同而已.从Vs2010的控件栏上拖过来的Map控件默认添加的底图是Esr ...
- Scala的类与类型
类和类型 List<String>和List<Int>类型是不一样的,但是jvm运行时会采用泛型擦除.导致List<String>和List<Int>都 ...
- 1107 Social Clusters[并查集][难]
1107 Social Clusters(30 分) When register on a social network, you are always asked to specify your h ...
- Singapore retailer will release this adidas NMD R1
Select spots are restocking the adidas NMD Singapore this Friday, Feb 24th featuring three different ...
- VS2010/MFC编程入门之二十三(常用控件:按钮控件的编程实例)
上一节VS2010/MFC编程入门教程中鸡啄米讲了按钮控件Button.Radio Button和Check Box的基本用法,本节就继续讲按钮控件的内容,通过一个实例让大家更清楚按钮控件在实际的软件 ...
- 15信号sigaction
信号处理 信号值小于 SIGRTMIN 的信号 (1~31) 都是不可靠信号 某些unix版本中,调用信号函数处理后会自动恢复默认信号处理,所以在信号处理函数中还需要继续调用signal函数设置信号处 ...