poj 3696 The Luckiest number 歐拉函數在解a^x=1modm的應用,pojluckiest

來源:互聯網
上載者:User

poj 3696 The Luckiest number 歐拉函數在解a^x=1modm的應用,pojluckiest

題意:

給一個L,求長度最小的全8數滿足該數是L的倍數。

分析:

轉化為求方程a^x==1modm。之後就是各種數學論證了。

代碼:

//poj 3696//sep9#include <iostream>#include <algorithm>using namespace std;typedef long long ll;ll L;ll factor[65536];ll mul(ll x,ll y,ll p){ll ret=0;while(y){if(y&1)ret=(ret+x)%p;x=(x+x)%p;y>>=1;}return ret;}ll pow(ll x,ll n,ll m){ll ret=1;x%=m;while(n){if(n&1)ret=mul(ret,x,m);x=mul(x,x,m);n>>=1;}return ret;}ll euler(ll n){ll ret=n;for(ll i=2;i*i<=n;++i)if(n%i==0){ret=ret/i*(i-1);while(n%i==0)n/=i;}if(n>1)ret=ret/n*(n-1);return ret;}ll cal(){ll m=L*9;for(int i=0;i<3;++i)if(m%2==0)m/=2;else break;if(m%2==0||m%5==0)return 0;ll phi=euler(m);int idx=0;for(ll i=1;i*i<=phi;++i)if(phi%i==0)factor[idx++]=i,factor[idx++]=phi/i;sort(factor,factor+idx);for(int i=0;i<idx;++i)if(pow(10,factor[i],m)==1)return factor[i];}int main(){int cases=0;while(scanf("%I64d",&L)==1&&L){printf("Case %d: ",++cases);printf("%I64d\n",cal());}return 0;} 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.