日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Poj 1284 Primitive Roots

發布時間:2023/12/3 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Poj 1284 Primitive Roots 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

    • Description
    • 題意:
    • 題解:
    • 代碼:

Poj 1284

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6485 Accepted: 3697

Description

We say that integer x, 0 < x < p, is a primitive root modulo odd prime
p if and only if the set { (xi mod p) | 1 <= i <= p-1 } is equal to {
1, …, p-1 }. For example, the consecutive powers of 3 modulo 7 are
3, 2, 6, 4, 5, 1, and thus 3 is a primitive root modulo 7. Write a
program which given any odd prime 3 <= p < 65536 outputs the number of
primitive roots modulo p.

Input

Each line of the input contains an odd prime numbers p. Input is
terminated by the end-of-file seperator.

Output

For each p, print a single number that gives the number of primitive
roots in a single line.

Sample Input

23 31 79

Sample Output

10 8 24

題意:

給定一個p,存在一個x,使得xi%p的值的集合(i的范圍是1~p-1)是{1,2…p-1},求出x是多少?

題解:

數論題,涉及歐拉公式
先介紹一個概念:
設m是正整數,a是整數,若a模m的階等于φ(m),則稱a為模m的一個原根。(其中φ(m)表示m的歐拉函數)
假設一個數g對于P來說是原根,那么gi mod P的結果兩兩不同,且有 1<g<P, 0<i<P,那么g可以稱為是P的一個原根,歸根到底就是g(P-1) = 1 (mod P)當且僅當指數為P-1的時候成立.(這里P是素數).
選自百度百科
結合到本題,x就是p的一個原根,那我們只需要找到滿足xp-1=1(mod P)這個式子就可以,這個式子也就是歐拉公式的φ(p-1)
歐拉公式的講解可以看這里

代碼:

#include<iostream> using namespace std; typedef long long ll; ll Euler(ll n){ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){n/=i;res=res-res/i;}while(n%i==0)n/=i;}if(n>1)res=res-res/n;return res; } int main() {int p;while(cin>>p){cout<<Euler(p-1)<<endl;}return 0; } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Poj 1284 Primitive Roots的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。