Lingyuan (seals. CPP/C/PAS)

Source: Internet
Author: User

The value of P (m) is the number of positive factors of m (including 1 and M ).

Returns the minimum value of X that satisfies p (x) = n.

For any positive integer N, there are n = p1 ^ A1 * P2 ^ A2 * P3 ^ A3 *...... * PN ^ An; (PI is a prime number)
Number of factors of N (A1 + 1) * (A2 + 1) * (A3 + 1 )*...... * (An + 1 );

For example, 8 = 2*2*2;
2 ^ 1*3 ^ 1*5 ^ 1 = 30;
Because 8 can also be decomposed into this form: 8 = 2*4; 2 ^ 3*3 ^ 1 = 24;

The correct answer is 24.

Assume there is a number of N = b1 * B2 * B3 *...... * Bi *...... * Bn;
If we break it down into n = b1 * B2 * B3 *...... * (Bj * bi )*...... * B [I-1] * B [I + 1] *... * Bn. The calculated result is smaller than the above formula,
This condition must be met:
P [n-I + 1] ^ Bi * P [n-J + 1] ^ (bj)> P [n-J + 1] ^ (Bj * bi)
Get P [n-J + 1] ^ (bj:
P [n-I + 1] ^ Bi> P [n-J + 1] ^ (Bj * (bi-1 ));
If this condition is met, you can assign BJ to BJ * Bi and assign Bi to 0, which indicates clearing;
Then you can.

 

The Code is as follows:

#include<iostream>#include<cmath>#include<cstdio>using namespace std;int prime[]={0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,89,97,101,103,107,109,113,127,131,137,139};int n,i,temp,a[1000]={0},j,ans[10000][2],c[10000];double pro(int x,int y){    double ans=x,t=x;    int c[100],i;c[0]=0;    while (y!=0){c[++c[0]]=y%2;y/=2;}    for (i=c[0]-1;i>=1;i--){        ans*=ans;        if(c[i]==1)ans*=t;    }    return ans;}void clean(){    int i,j;    for(i=1;i<=a[0];i++)        for(j=a[0];j>i;j--)        if(a[i]*a[j]!=0)            if (pro(prime[a[0]-i+1],a[i]-1)>pro(prime[a[0]-j+1],a[j]*(a[i]-1)))            {               a[j]*=a[i]; a[i]=0; break;            }}int main(){    freopen("seals.in","r",stdin);    freopen("seals.out","w",stdout);    scanf("%d",&n);    for    (i=2;i<=sqrt(n);i++)     while (n%i==0) { a[++a[0]]=i; n/=i;}     if (n>1)a[++a[0]]=n;      clean();      int tot=0,t;       for (i=1;i<=a[0];i++)    if (a[a[0]-i+1]>0){         temp=a[a[0]-i+1]-1;           ans[++tot][1]=prime[i];           ans[tot][2]=temp;    }    for (i=1;i<tot;i++) printf("%d^%d*",ans[i][1],ans[i][2]);     printf("%d^%d",ans[tot][1],ans[tot][2]); }
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.