acwing 873. 欧拉函数 模板
地址 https://www.acwing.com/problem/content/875/
给定n个正整数ai,请你求出每个数的欧拉函数。 欧拉函数的定义
输入格式
第一行包含整数n。 接下来n行,每行包含一个正整数ai。 输出格式
输出共n行,每行输出一个正整数ai的欧拉函数。 数据范围
≤n≤,
≤ai≤∗
输入样例: 输出样例:
题解
模板题 根据公式可得代码中注释部分的代码 然后避免出现分数 调整了计算次序 并做了一些通分 方便计算
#include <iostream> using namespace std; int phi(int x)
{
int res = x;
for (int i = ; i <= x / i; i ++ )
if (x % i == )
{
res = res*(-/i); // = res*((i-1)/i) = res/i*(i-1)
//res = res / i * (i - 1); //最终结果
while (x % i == ) x /= i;
}
if (x > ) res = res / x * (x - ); return res;
} int main()
{
int n;
cin >> n;
while (n -- )
{
int x;
cin >> x;
cout << phi(x) << endl;
} return ;
}
acwing 873. 欧拉函数 模板的更多相关文章
- AcWing 873. 欧拉函数
//用定义直接求 #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; while( ...
- UVA 10820 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- hdu3501Calculation 2——欧拉函数模板
题目: Problem Description Given a positive integer N, your task is to calculate the sum of the positiv ...
- poj2407(欧拉函数模板)
sqrt(n)复杂度 欧拉函数模板 #include <iostream> #include <cstdio> #include <queue> #include ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- P2158 [SDOI2008] 仪仗队(欧拉函数模板)
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- hdu1286 找新朋友 欧拉函数模板
首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!! 欧拉函数求的就是题目要求的数. 关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板. 在这一题的讨论里看到的. ...
- 快速切题 sgu102.Coprimes 欧拉函数 模板程度 难度:0
102. Coprimes time limit per test: 0.25 sec. memory limit per test: 4096 KB For given integer N (1&l ...
随机推荐
- VMware Workstation15激活码
VG5HH-D6E04-0889Y-QXZET-QGUC8 亲测可用
- pandas 过滤
条件过滤 通过loc进行行过滤,也可对过滤后的行进行赋值 import pandas as pd df = pd.DataFrame({"name": ["yang&qu ...
- Bootstrap4 本地编译运行
Step1. 获取Bootstrap源代码 https://github.com/twbs/bootstrap Step2. 进入目录并切换npm源 npm --registry https://re ...
- MyBatis初体验
一.MyBatis 1.简介 曾命名IBatis(老版本), 交给Google维护后,改名为MyBatis(新版本).学习文档: https://mybatis.org/mybatis-3/zh/in ...
- NETGEAR R7800路由器TFTP刷回原厂固件方法
前几天因图新鲜将用了一年的R7800刷为dd-wrt固件,结果发现信号覆盖和网络速率相对于原厂固件还有一些差距. 然后从dd-wrt固件刷回原厂,具体操作过程如下: 1.到NETGEAR官网[支持]模 ...
- 8 个 Tips 让你更好的进行 Code Review
摘要: Code Review 可以提高代码质量. 原文:Elevenbeans 作者:前端小智 Fundebug经授权转载,版权归原作者所有. 原文地址:https://kellysutton.co ...
- enable user-defined extended attributes for ext3 file systems; 增加ext3 文件系统的扩展属性;
To enable user-defined extended attributes for ext3 file systems (i.e. device), use: tune2fs -o user ...
- UDP组播
多播(组播) 组播组可以是永久的也可以是临时的.组播组地址中,有一部分由官方分配的,称为永久组播组.永久组播组保持不变的是它的ip地址,组中的成员构成可以发生变化.永久组播组中成员的数量都可以是任意的 ...
- 如何使用1行代码让你的C++程序控制台输出彩色log信息
本文首发于个人博客https://kezunlin.me/post/a201e11b/,欢迎阅读最新内容! colorwheel for colored print and trace for cpp ...
- Nginx安装及配置反向代理
本片博客记录在ubuntu16下安装nginx,以及如何实现负载均衡 安装nginx 如果是新机器,安装相关依赖环境 sudo apt install build-essential sudo apt ...