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. 4Sum II

    https://leetcode.com/submissions/detail/153740275/ class Solution { public: int fourSumCount(vector& ...

  2. Python文件与异常处理

    文件读写 使用python的BIF(build in function)open()进行文件读写操作 # 1.打开文件 data = open(file_name,'w') # 读取模式有很多种,主要 ...

  3. 分治 - 计算几何 - BZOJ2458,[BeiJing2011]最小三角形

    http://www.lydsy.com/JudgeOnline/problem.php?id=2458 [BeiJing2011]最小三角形 描述 Frisk现在遇到了一个有趣的问题. 平面上有N个 ...

  4. laravel5.2总结--服务提供者,契约(Contracts)

    首先理解两个概念 1.契约:一组定义了框架核心服务的接口 2.服务提供者:所有 Laravel 应用程序启动的中心所在. 包括你自己的应用程序,以及所有的 Laravel 核心服务,都是通过服务提供者 ...

  5. Python抓取视频内容

    Python抓取视频内容 Python 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年.Python语法简洁而清晰,具 ...

  6. ASP.NET Core 利用中间件支持跨域请求

    方法1: 在Startup的ConfigureServices()中添加services.AddCors()在Startup的Configure()中添加app.UseCors(); 保证其在app. ...

  7. loadrunner11使用wplus_init_wsock录制非IE脚本/手机抓包

    假如你的IE版本号太高,或者是chrome,firfox,又或者想录手机上的包,可以用loadrunner的wplus_init_wsock工具   1.在创建LR脚本的Start Recording ...

  8. c++ stl在acm的入门及使用

    stl的全称为Standard Template Library,即为标准模板库,它主要依赖于模板,而不是对象,所以你需要对这个模板进行实例化,选择你要使用的类型.我们用的都是一些简单的容器吧 这里可 ...

  9. web自动化测试:watir+minitest(三)

    本文,谢绝转载. 整体框架设计: 1.用例的解耦性.一个测试用例一个脚本.而并非minitest中的N个test写在一个文件中 2.单独调试与全量连跑或部分连跑 3.任意变量.参数配置.这点对后期维护 ...

  10. redhat linux 7.4关闭透明大页

    每一步: 在GRUB_CMDLINE_LINUX加入选项 transparent_hugepage=never echo 'GRUB_CMDLINE_LINUX="transparent_h ...