Become A Hero

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 210    Accepted Submission(s): 57

Problem Description
Lemon
wants to be a hero since he was a child. Recently he is reading a book
called “Where Is Hero From” written by ZTY. After reading the book,
Lemon sends a letter to ZTY. Soon he recieves a reply.

Dear Lemon,
It is my way of success. Please caculate the algorithm, and secret is behind the answer. The algorithm follows:
Int Answer(Int n)
{
.......Count = 0;
.......For (I = 1; I <= n; I++)
.......{
..............If (LCM(I, n) < n * I)
....................Count++;
.......}
.......Return Count;
}
The LCM(m, n) is the lowest common multiple of m and n.
It is easy for you, isn’t it.
Please hurry up!
ZTY

What a good chance to be a hero. Lemon can not wait any longer. Please help Lemon get the answer as soon as possible.

 
Input
First
line contains an integer T(1 <= T <= 1000000) indicates the
number of test case. Then T line follows, each line contains an integer n
(1 <= n <= 2000000).
 
Output
For each data print one line, the Answer(n).
 
Sample Input
1
1
 
Sample Output
0
 
LCM(a,b)=a*b/gcd(a,b) 如果 要LCM(a,b) < a*b 那么gcd(a,b)不能为1,所以题目就转换成了 1-n 内与n不互质的数有多少个了。利用欧拉函数求出互质的个数,减掉就是答案。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long LL;
const int N = ;
int euler[N];
void getEuler()
{
memset(euler,,sizeof(euler));
euler[] = ;
for(int i = ; i <= N; i++){
if(!euler[i])
for(int j = i; j <= N; j+= i)
{
if(!euler[j])
euler[j] = j;
euler[j] = euler[j]/i*(i-);
}
}
} int main()
{
getEuler();
int tcase;
scanf("%d",&tcase);
while(tcase--){
int n;
scanf("%d",&n);
printf("%d\n",n-euler[n]);
}
return ;
}

hdu 2654(欧拉函数)的更多相关文章

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. hdu 2824(欧拉函数)

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  5. 找新朋友 HDU - 1286 欧拉函数模板题

    题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...

  6. hdu 2824 欧拉函数 O(nlogn) 和O(n)

    裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...

  7. hdu 4983 欧拉函数

    http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...

  8. hdu 4002 欧拉函数 2011大连赛区网络赛B

    题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是 ...

  9. hdu 1787(欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 常用自写函数[更新ing]

    int gcd (int x, int y)//最大公约数 { return y == 0 ? x : gcd( y , x % y ); } int lcm(int x, int y)//最小公倍数 ...

  2. 指针的操作 p*++

    int x, y, *px = &x, *py = &y; y = *px + ; //表示把x的内容加5并赋给y,*px+5相当于(*px)+5 y = ++*px; //px的内容 ...

  3. python基础——18(面向对象2+异常处理)

    一.组合 自定义类的对象作为另一个类的属性. class Teacher: def __init__(self,name,age): self.name = name self.age = age t ...

  4. HDU 1535 S-Nim(SG函数)

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. 谋哥:《App自推广》连载2直立人行走迁徙

    [谋哥每天一干货,第六十九篇] 前篇说到声音在远古时代,是一个神奇的东西,它能够很快地把信息传播到其他地方,突破了短距离.然而能人的后代直立人学会了直立行走,他们开始走出非洲,到达遥远的中东.中国,还 ...

  6. C#入门篇6-2:字符串操作 string常用的函数

    //String 字符串的常见操作 public static void Fun1() { string MyStr = " Hello World! "; //length长度属 ...

  7. C#入门篇5-7:流程控制语句 continue语句

    #region continue语句 public class ContinueApp { public static void Fun1() { //标签打印显示1…30,若能被3整除则不打印. ; ...

  8. Python框架之Django学习笔记(十二)

    Django站点管理 十一转眼结束,说好的充电没能顺利开展,反而悠闲的看了电视剧以及去影院看了新上映的<心花路放>.<亲爱的>以及<黄金时代>,说好的劳逸结合现在回 ...

  9. Windows网络编程笔记5 -- 其他套接字

    包括红外线套接字(IrSock).IPX/SPX 套接字.NetBIOS 套接字.AppleTalk 套接字.ATM 套接字等.对这些套接字进行简单介绍. 第一.红外线套接字(I r S o c k) ...

  10. python - 接口自动化测试 - ReadConfig - 读取配置文件封装

    # -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: read_config.py @ide: PyCharm ...