首页 > 其他分享 >POJ 2407 Relatives 欧拉函数(不打表)

POJ 2407 Relatives 欧拉函数(不打表)

时间:2023-02-07 12:36:37浏览次数:60  
标签:const int res ll long 2407 Relatives 打表 include


Relatives

Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 16563

 

Accepted: 8410

Description

Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.

Input

There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.

Output

For each test case there should be single line of output answering the question posed above.

Sample Input

7
12
0

Sample Output

6
4

算法分析:

裸的欧拉函数,不过打表不行,会超内存,数据很水,挨个求就行。

代码实现

#include<cstdio>  
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
using namespace std;
const double eps = 1e-8;
typedef long long ll;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;

const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN=5010;
const int MAXM=100010;
using namespace std;
ll phi(ll n)
{
ll res=n;
for(int i=2;i*i<=n;i++){
if(n%i==0){
res=res-res/i;
do{
n/=i;
}while(n%i==0);
}
}
if(n>1) res=res-res/n;
return res;
}



int main()
{

int n;
while(scanf("%d",&n)!=EOF)
{
if(n==0) break;
cout<<phi(n)<<endl;
}
return 0;
}

 

标签:const,int,res,ll,long,2407,Relatives,打表,include
From: https://blog.51cto.com/u_14932227/6041965

相关文章

  • poj 2262 Goldbach's Conjecture 素数打表
    Goldbach'sConjectureTimeLimit: 1000MS MemoryLimit: 65536KTotalSubmissions: 48891 Accepted: 18614DescriptionIn1742,ChristianGoldbach,aGermanamate......
  • WPF 使用 StaticResource、DynamicResource、RelativeSource
    StaticResource(静态资源)依赖属性静态资源在第一次编译后即确定其对象或值,之后不能对其进行修改。StaticResources的适用场合:(1)在资源第一次引用之后无需再修改资源的值。(2......
  • HDU6198 number number number(打表 矩阵快速幂)
    题意就是找到用K个斐波那契数组不成的最小的数字是谁。先打表找规律1421233348852326609可以发现递推规律:F[n]=4*(F[n-1]-F[n-2])+F[n-3]如果直接递推打......
  • POJ 2407 Relatives
    DescriptionGivenn,apositiveinteger,howmanypositiveintegerslessthannarerelativelyprimeton?Twointegersaandbarerelativelyprimeifth......
  • 更___的小数据打表/输出样例
    #include<bits/stdc++.h>#defineELputs("Elaina")#defineregregisterintusingnamespacestd;enumkawaii{yoshino=2,koishi=3,yomi=16}suki;inlinevoidMyDear......
  • L - Fenwick Tree Gym - 103861L(打表,树状数组)
    题意:一开始数组的每个数都是零对于每次操作:可以对一个数加上一个实数在加上实数的同时,对应的i+lowbit(i)一直到<=n都会加上这个实数不同操作可以加上不同的实......
  • POJ 1950(不打表做法)
    这题就是搜……注意设定maxn要不然肯定爆maxn=1*10^最大位数/21234..89-11121314这样的Programaa;constmaxn=1000000000000000;varn,t:longint;a:array[1..15]......
  • HDU 1431 素数回文——————离线暴力打表
    素数回文TimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):23585AcceptedSubmission(s):5550ProblemDescript......
  • TMS320LF2407数字采样
    1引言模数(AD)转换通常是数字信号处理应用中的第一步,依据应用的不同,对模数转换器(ADC)也有不同的要求,衡量模数转换器的最重要的标准是它的转换速率、分辨率和精度。应......
  • 使用打表法找规律
    使用打表法找规律作者:Grey原文地址:博客园:使用打表法找规律CSDN:使用打表法找规律打表法的使用条件打表法适合:输入简单,输出也简单(只有一个数),可以暴力把一部分结果打印......