栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1365 Prime Land

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1365 Prime Land

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int mr=40000;bool notp[mr];int pr[mr];int pn;void getpri()//筛素数{    pn=0;    memset(notp,0,sizeof(notp));    for(int i=2; i<mr; i++)    {        if(!notp[i])        { pr[pn++]=i;        }        for(int j=0; j<pn && i*pr[j]<mr; j++)        { int k=i*pr[j]; notp[k]=1; if(i%pr[j]==0) {     break; }        }    }}int power(int a,int n){    if(n==0)        return 1;    else if(n==1)        return a;    else if(n&1)        return a*power(a*a,n>>1);    else        return power(a*a,n>>1);}char s[100000];int main(){    getpri();    while(gets(s))    {        if(s[0]=='0') break;        int a,b,sum=1,i=0;        while(s[i]!='')        { a=0,b=0; while(s[i]!=' '&&s[i]!='') {     a=a*10+(s[i]-'0');     i++; } i++; while(s[i]!=' '&&s[i]!='') {     b=b*10+(s[i]-'0');     i++; } sum*=power(a,b); if(s[i]=='')     break; i++;        }        sum--;        int stk[40000][2],top=0;        for(int i=0;i<pn&&pr[i]<=sum;i++)        { if(sum%pr[i]==0) {     b=0;     a=pr[i];     while(sum%a==0)     {         sum/=a;         b++;     }     stk[top][0]=a;     stk[top][1]=b;     top++; }        }        --top;        printf("%d %d",stk[top][0],stk[top][1]);        for(--top;top>=0;top--)        { printf(" %d %d",stk[top][0],stk[top][1]);        }        printf("n");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372633.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号