POJ 2480 积性函数 欧拉函数
Burnside引理 Polya定理

POJ 1091 扩展欧拉函数

scturtle posted @ 2010年7月20日 05:15 in algorithm , 3541 阅读

 欧拉函数F(n)=n \prod_{p|n}(1-\frac{1}{p})的概率解释:

1/p看做从1~n中某数有n的因子p的概率,则1-1/p是没有因子p的概率,最前面的n是指1~n的数的个数,由乘法公式可见F的意义

此题设函数F(n,m)为公因子为1的排列的个数,易见当m为质数时 F(n,m)=m^n-1

普遍看,总排列个数为m^n,取p|m,则1/p为1~m的某数有因子p的概率,1/{p^n}为前n个数都有p因子的概率,即这n+1个数有公因子p的概率

所以由乘法公式见:

F(n,m)=m^n\prod_{p|n}(1-\frac{1}{p^n})

恩,我理解的大概就是这个样子了...

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef unsigned long long u64 ;
#define maxn 100010
u64 primet [ maxn ];
int pnum = 0 ;
void getprimtable()
{
    bool flag [ maxn ] = { false };
    for (long i = 2 ; i < maxn ; i ++)
    {
        if (! flag [ i ])
        {
            primet [ pnum ++] = i ;
            for (u64 j = i * i ; j < maxn ; j += i) flag [ j ] = true ;
        }
    }
}

bool isprime(u64 m)
{
    bool prime = 1;
    for (int i = 0; primet[i]*primet[i] <= m; i++)
    {
        if (m % primet[i] == 0)
        {
            prime = 0;
            break;
        }
    }
    return prime;
}

u64 pow64(u64 a, u64 b)
{
    u64 ans = 1, t = a;
    while (b)
    {
        if (b & 1)
        {
            ans *= t;
            b--;
        }
        t *= t;
        b >>= 1;
    }
    return ans;
}
u64 n, m;
int main()
{
    //freopen("in.txt", "r", stdin);
    getprimtable();
    u64 ans, t;
    while (cin >> n >> m)
    {
        ans = pow64(m, n);
        if (isprime(m))
            cout << ans - 1 << endl;
        else
        {
            for (u64 i = 0; primet[i]*primet[i] <= m; i++)
            {
                if (m % primet[i] == 0)
                {
                    while (m % primet[i] == 0) m /= primet[i];
                    t = pow64(primet[i], n);
                    ans = ans / t * (t - 1);
                }
            }
            if (m != 1)
            {
                t = pow64(m, n);
                ans = ans / t * (t - 1);
            }
            cout << ans << endl;
        }
    }
}

 

home cleaning dubai 说:
2021年9月19日 14:51

Better you allow for clutters to build up in your own home the more of their time it's important to pay to get cleaning expert services. Conduct real estate survey and find out all the ones has to be decluttered. One procedure for classifying them will be to determine whether you may have used this item prior to now six many months.

civaget 说:
2023年12月12日 03:37

Join the conversation on 구글 상위노출 strategies and share your insights with the SEO community. Collaboration can lead to innovative solutions.

civaget 说:
2023年12月21日 19:04

Discover the magic of 제주오피 for yourself. It's where convenience and quality converge.

civaget 说:
2023年12月24日 21:38

Dive into 해외스포츠중계 for unparalleled sports excitement.

civaget 说:
2023年12月25日 21:07

오피타임 stands out with its comprehensive business profiles and real-time updates.

civaget 说:
2024年1月02日 20:38

I've had a blast every time I've visited High Kick 레깅스룸. It's become my favorite spot in Gangnam for a reason!

jnanabhumiap.in 说:
2024年1月11日 00:39

JNANABHUMI AP provides a CBSE syllabus for all classes for the academic year 2024 has been designed as per the guidelines of the CBSE Board. The syllabus offers a conceptual background and lays the groundwork for the Class 10 Board exams. jnanabhumiap.in By visiting the page, students will find the downloadable pdf of the reduced CBSE 10th Syllabus along with the deleted portion of the syllabus for each subject. So, students are advised to prepare for the exam, as per the syllabus mentioned here.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter