题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705

撕逼题。不就是枚举gcd==d,求和phi[ n/d ]么。

然后预处理sqrt (n)的阶乘,RE得不行。发现用到了大于sqrt (n)的阶乘。

然后翻看TJ。

发现phi可以现求!就用那个式子。我竟然都忘了!

注意最后剩下的一个大于sqrt (i)的质因数。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
const int N=1e5+;
ll ans,n;
ll phi(ll a)
{
ll ret=a;
for(ll i=;i*i<=a;i++)
if(a%i==)
{
ret=ret/i*(i-);
while(a%i==)a/=i;
}
if(a>)ret=ret/a*(a-);
return ret;
}
int main()
{
scanf("%lld",&n);
for(ll i=;i*i<=n;i++)
if(n%i==)
if(i!=n/i)ans+=i*phi(n/i)+(n/i)*phi(i);
else ans+=i*phi(n/i);
printf("%lld\n",ans);
return ;
}

bzoj 2705 [SDOI2012]Longge的问题——欧拉函数大水题的更多相关文章

  1. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  2. Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][ ...

  3. bzoj 2705: [SDOI2012]Longge的问题 歐拉函數

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1035  Solved: 669[Submit][S ...

  4. 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数

    题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...

  5. BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)

    题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...

  6. [SDOI2012] Longge的问题 - 欧拉函数

    求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...

  7. UVA 10820 欧拉函数模板题

    这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...

  8. POJ 2407 Relatives(欧拉函数入门题)

    Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...

  9. hdu 1286 找新朋友 欧拉函数模版题

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Des ...

随机推荐

  1. 01.visual studio 2017添加菜单

    创建项目 文件--新建项目 如果新建项目 左侧没有扩展菜单,请安装即可 添加菜单 右键--添加新项 菜单设置 菜单设置文件: MyCommandPackage.vsct <Buttons> ...

  2. PAT甲级——【牛客练习题100】

    题目描述 Given N rational numbers in the form "numerator/denominator", you are supposed to cal ...

  3. myeclipse工程更新后java图标变为空心的解决办法

    今天用svn更新了工程发现目录结构改变了,同时所有的java文件的图标变成了空心的.解决办法如下 1.右键单击工程目录名,选择properties. 2.选择java bulid path,正常的应该 ...

  4. storm一些可调节的参数

    # Licensed to the Apache Software Foundation (ASF) under one   # or more contributor license agreeme ...

  5. NoSQL与关系数据库的比较

  6. springboot核心技术(四)-----Docker、数据访问、自定义starter

    Docker 1.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使 用这个镜 ...

  7. C++星号的含义

    [转载] [http://blog.sina.com.cn/s/blog_4a50d85b0100uk3c.html]   1.乘法运算符   2.定义指针 int *p = 0; 还是 int* p ...

  8. SQLServer-SQLServer2017:SQLServer2017

    ylbtech-SQLServer-SQLServer2017:SQLServer2017 微软推出了首个公共预览版本,并持续带来更新和改进.而今天,微软同时向 Windows.Linux.macOS ...

  9. 取消 ios 上下滑动

  10. PAT甲级——A1053 Path of Equal Weight

    Given a non-empty tree with root R, and with weight W​i​​ assigned to each tree node T​i​​. The weig ...