ZOJ 2562 HDU 4228 反素數

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   for   2014   art   

反素數:

對於任何正整數x,起約數的個數記做g(x).例如g(1)=1,g(6)=4.

如果某個正整數x滿足:對於任意i(0<i<x),都有g(i)<g(x),則稱x為反素數.

ZOJ 2562 反素數

因為寫了POJ 2886的線段樹,然后里面有反素數,以前沒遇到過,所以先搞這兩題普及一下知識再說。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define INF 510010#define maxn 400010using namespace std;typedef long long ll;typedef unsigned long long ull;ll prime[20]={2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,53};ll n;ll bestcurr;//bestcurr 相同最大因數個數中值最小的數ll largecnt;//largecnt:n範圍內最大的因數個數void getarcprime(ll curr,int cnt,int limit,int k){    if(curr>n) return ;    if(largecnt<cnt)//此時枚舉到的因數個數比之前記錄的最大的因數個數要大,就替換最大因數個數    {        largecnt=cnt;        bestcurr=curr;    }    if(largecnt==cnt && bestcurr>curr)//替換最優值        bestcurr=curr;    ll temp=curr;    for(int i=1;i<=limit;i++)    {        temp=temp*prime[k];        if(temp>n) return;        getarcprime(temp,cnt*(i+1),i,k+1);    }}int main(){    while(scanf("%lld",&n)!=EOF)    {        bestcurr=0;        largecnt=0;        getarcprime(1,1,50,0);        printf("%lld\n",bestcurr);    }    return 0;}
HDU 4228
這題就是上題的延伸吧,就是求出每個然後打表。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define INF 510010#define maxn 400010using namespace std;typedef long long ll;typedef unsigned long long ull;ll p[1010];ll prime[30]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};void getartprime(ll cur,int cnt,int limit,int k){    //cur:當前枚舉到的數;    //cnt:該數的因數個數;    //limit:因數個數的上限;2^t1*3^t2*5^t3……t1>=t2>=t3……    //第k大的素數    if(cur>(1LL<<60) || cnt>150) return ;    if(p[cnt]!=0 && p[cnt]>cur)//當前的因數個數已經記錄過且當時記錄的數比當前枚舉到的數要大,則替換此因數個數下的枚舉到的數        p[cnt]=cur;    if(p[cnt]==0)//此因數個數的數還沒有出現過,則記錄        p[cnt]=cur;    ll temp=cur;    for(int i=1; i<=limit; i++) //枚舉數    {        temp=temp*prime[k];        if(temp>(1LL<<60)) return;        getartprime(temp,cnt*(i+1),i,k+1);    }}int main(){    int n;    getartprime(1,1,75,0);    for(int i=1; i<=75; i++)    {        if(p[i*2-1]!=0 && p[i*2]!=0)            p[i]=min(p[i*2-1],p[i*2]);        else if(p[i*2]!=0) p[i]=p[i*2];        else p[i]=p[i*2-1];    }    while(scanf("%d",&n),n)        printf("%I64d\n",p[n]);    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.