第十届 吉林省赛 E

Counting fractions

TimeLimit: 2000MS  MemoryLimit: 65536 Kb

Totalsubmit: 39   Accepted: 6  

Description

Consider the fraction, n/d, where n and d are positive integers. If <= d and HCF(n,d)=1, it is called a reduced proper fraction.

If we list the set of reduced proper fractions for d <= 8 in ascending order of size, we get:

1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8

It can be seen that there are 21 elements in this set.

How many elements would be contained in the set of reduced proper fractions for d <= x?

Input

The input will consist of a series of x, 1 < x < 1000001.

Output

For each input integer x, you should output the number of elements contained in the set of reduced proper fractions for d <= x in one line.

Sample Input

3

8

Sample Output

3
21


比赛的时候思维进入怪圈,改了半天都改不过 数论知识点匮乏啊


首先贴一个定理


正整数n,欧拉函数是小于n的正整数中与n互质的数的数目(φ(1)=1)。此函数以其首名研究者欧拉命名(Euler'so totient function),它又称为Euler's totient function、φ函数、欧拉商数


通式:
 
其中p1, p2……pn为x的所有质因数,x是不为0的整数。
φ(1)=1(唯一和1 互质的数(小于等于1)就是1本身)。
注意:每种质因数只一个。 比如12=2*2*3那么φ(12)=12*(1-1/2)*(1-1/3)=4
若n是质数p的k次幂,
   
,因为除了p的倍数外,其他数都跟n互质。
设n为正整数,以 φ(n)表示不超过n且与n互素的正整数的个数,称为n的欧拉函数值
φ:N→N,n→φ(n)称为欧拉函数。
欧拉函数是 积性函数——若m,n互质,
 
特殊性质:当n为奇数时,
   
, 证明与上述类似。
若n为质数则
 
AC代码


#include <iostream>
#include <math.h>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
#define maxn 1011000
typedef long long ll;
const int inf = 1e9+7;
int prime[maxn]; //素数表
ll ans[maxn];
void getprime(){
    prime[2]=0;
    for(int i = 2 ; i<maxn ; i++)
        ans[i]=i;
    for(int i = 2 ; i<maxn ; i++){
        if(!prime[i]){
            p[pnum++]=i;
            ans[i]=i-1;
            for(int j = i*2 ; j<maxn ; j+=i){
                prime[j]=1;
                ans[j]=ans[j]/i*(i-1);
            }
        }
    }
}
int main(){
    getprime();
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        ll sum=0;
        scanf("%d",&n);
        for(int i = 2 ; i<=n ; i++){
            sum+=ans[i];
            sum=sum%inf;
        }
        printf("%lld\n",sum);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值