\(\text{Solution}\)

\[ans = \frac{1}{n}\sum_{i=1}^n n^{(i,n)} = \frac{1}{n}\sum_{d|n}n^d\varphi(\frac{n}{d})
\]

\(T\) 组数据,然而暴力计算就可以过

可靠点就用哈希表存下(然而更慢

\(\text{Code}\)

#include <cstdio>
#define RE register
#define IN inline
using namespace std;
typedef long long LL; const int P = 1e9 + 7;
int n, t, tot;
LL ans; IN int gcd(int x, int y){return (!y ? x : gcd(y, x % y));}
IN LL fpow(LL x, int y){LL s = 1; for(; y; y >>= 1, x = x * x % P) if (y & 1) s = s * x % P; return s;}
IN int getphi(int x)
{
int res = x;
for(RE int i = 2; i * i <= x; i++)
if (x % i == 0)
{
res = res / i * (i - 1);
while (x % i == 0) x /= i;
}
if (x > 1) res = res / x * (x - 1);
return res;
} int main()
{
scanf("%d", &t);
for(; t; --t)
{
scanf("%d", &n), ans = 0;
for(RE int i = 1; i * i <= n; i++)
if (n % i == 0)
{
ans = (ans + fpow(n, i) * getphi(n / i) % P) % P;
if (i * i != n) ans = (ans + fpow(n, n / i) * getphi(i) % P) % P;
}
printf("%lld\n", ans * fpow(n, P - 2) % P);
}
}

最新文章

  1. SecureCRT上传和下载文件
  2. CSS3学习内容与心得
  3. Java提高篇——equals()与hashCode()方法详解
  4. [jQuery学习系列三 ]3-JQuery学习二-字典操作
  5. 默认调用电脑IE版本最高版本
  6. ios中怎么获得当前版本号
  7. 51nod-正整数分组问题(基础方程DP-01背包)
  8. BC 2015在百度之星程序设计大赛 - 预赛(1)(KPI-树董事长)
  9. WinForm酒店管理软件--框架
  10. SQL Server 文件结构 与 全局变量,函数
  11. MQ NameServer模块划分
  12. CentOS6下安装git
  13. (六十六)TableView内容超过一屏时滚动到屏幕底部的方法
  14. Actor消息发送及等待结果关键字
  15. angular.isNumber()
  16. Specified key was too long; max key length is 767 bytes解决方案
  17. Python档案袋( 时间 和 随机数 模块 )
  18. 29. SpringBoot Redis 非注解
  19. [原]Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused
  20. CentOS7中部署Showdoc

热门文章

  1. .NET MAUI 安卓应用开发初体验
  2. SSH(五)spring整合hibernate
  3. 数电第8周周结_by_yc
  4. mysql安装及访问配置
  5. Zabbix技术分享——使用Zabbix6.0监控业务日志
  6. 【终极解决办法】pyinstaller打包exe没有错误,运行exe提示Failed to execute script &#39;mainlmageWindows&#39; due tounhandled exception: No module named &#39;docx&#39;
  7. 【实战】Hadoop安装01-伪分布式-Pseudo
  8. 【每日一题】【将cur的next尾插到pre后面,尾插k-1次】25. K 个一组翻转链表-211115&amp;220120
  9. 命令指定IP端口号
  10. windows 、linux文件互传-FileZilla