hdu 2654(欧拉函数)
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
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.
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).
1
#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(欧拉函数)的更多相关文章
- hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...
- hdu 2824(欧拉函数)
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1395(欧拉函数)
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 3307(欧拉函数+好题)
Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- 找新朋友 HDU - 1286 欧拉函数模板题
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...
- hdu 2824 欧拉函数 O(nlogn) 和O(n)
裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...
- hdu 4983 欧拉函数
http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...
- 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是 ...
- hdu 1787(欧拉函数)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- python3 练习题100例 (十五)
这个比较难,主要难在考虑的问题太多,有好几个还没写出来.有空再来改进.请高手指教! #!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ ...
- 添加SQL字段
通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数增加字段: alter table [表名] add 字段名 smallin ...
- HDU:3336-Count the string(next数组理解)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pr ...
- IQueryable与IEnumerable区别
前者可以延迟加载,即执行完后不马上执行数据库语句,用到再加载.
- 裸奔着造房子——对政府禁止采购Win8系统的一些看法
前段时间有消息称政府招标的项目将禁止使用Win8系统,原因是Win8系统的安全架构将有利于暴露敏感信息给微软,而微软的老子是美利坚,老子想要知道什么,儿子当然不敢不从.因此Win8也被打入冷宫,微软多 ...
- Linux程序编辑器习题汇总
简答题部分: 1.我用vi开启某个档案后,要在第34行向右移动15个字符,应该在一般模式中下达什么指令? (1)先按下34G到34行:(2)再按下[l5+向右键],或[l5l]亦可! 2.在vi开启的 ...
- 设计模式之第6章-迭代器模式(Java实现)
设计模式之第6章-迭代器模式(Java实现) “我已经过时了,就不要讲了吧,现在java自带有迭代器,还有什么好讲的呢?”“虽然已经有了,但是具体细节呢?知道实现机理岂不美哉?”“好吧好吧.”(迭代器 ...
- 转:vc与界面开发之间的文章
[很好的一篇文章,很喜欢看同行的心路历程:http://www.vckbase.com/index.php/nv/444.html] 本屌丝在新春放假期间闲来无事,在各大编程论坛溜达了一圈.发现年前的 ...
- [netty4][netty-transpot]Channel体系分析
Channel体系分析 接口与类结构体系 -- [I]AttributeMap, ChannelOutboundInvoker, Comparable -- [I]AttributeMap ---- ...
- Python-S9-Day116——Flask框架相关
01 内容回顾 02 Flask框架:路由和视图(一) 03 Flask框架:路由和视图(二) 04 Flask框架:路由和视图(三) 05 Flask框架:路由和视图(四) 06 Flask框架:s ...