Number (number theory) of about 14 A n cattle off practice match

Links: https://ac.nowcoder.com/acm/contest/82/A
Source: Cattle-off network

Time limit: C / C ++ 1 second, 2 seconds languages other
space restrictions: C / C ++ 262144K, other languages 524288K
64bit the IO the Format: LLD%

Title Description

t interrogation times, each time you give a number n, find the [. 1 n,] within a maximum number submultiple of the number of count about

Enter a description:

The first line of a positive integer t 
after t rows each a positive integer n

Output Description:

Output t lines, each an integer that represents the answer
Example 1

Entry

copy
5
13
9
1
13
16

Export

copy
6
4
1
6
6

Remarks:

To 100% of the data, t <= 500, 1 < = n <= 1000000000000000000 ideas: a positive integer n, we can be the only decomposition n = p1 ^ (x1) * p2 ^ (x2) * p3 (x3) ... * pk ^ (xk) the number n is a divisor of (x1 + 1) * (x2 + 1) * (x3 + 1) * ... * (xk + 1) where p1 <p2 <p3 < p4 ... <pk and x1> x2> x3> x4> ...> xk then we can enumerate the number of n or less when the number according to the law of mass number to find the number of no greater than about the maximum number n . Another point to note is that, is not a power of a small number of quality is zero, while a power of greater than his prime number is not zero, because this is not the best. What we want is not the optimal maximum number, but the maximum number of divisor, divisor number can be seen from the above formula, if the power of the large prime numbers to the small primes, about the same number at the same time the number, total value of the smaller, more small value multiplied by a prime number, but also allows the number of divisor becomes large, it is possible to prove the above mentioned. Enumeration variable with a maximum limit to define a power of a prime number, because of the law of diminishing to meet a power of a prime number. , Details see the code:

















#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int noprime[maxn+5];
std::vector<int> p;
void getprime()
{
    int m=sqrt(maxn+0.5);
    for(int i=2;i<=m;i++)
    {
        for(int j=i*i;j<=maxn;j+=i)
        {
            noprime[j]=1;
        }
    }
    repd(i,2,maxn)
    {
        if(!noprime[i])
        {
            p.push_back(i);
        }
    }
}
ll a[500]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
ll ans=0ll;
ll n;
void dfs(ll x,int id,int limit,ll num)
{
    years = max (years, num);
    if (id> = 15 )
    {
        return ;
    }
    ll temp=a[id];
    for(int j=1;j<=limit;j++)
    {
        if(x<=n/temp)
        {
            dfs(x*temp,id+1,j,num*(j+1));
            temp*=a[id];
        }else
        {
            break;
        }
    }

}
int main ()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    
    int t;
    gbtb;
    // cout<<(1ll<<60)<<endl;
    // cout<<(ll)1e18<<endl;
    cin>>t;
    while(t--)
    {
        cin>>n;
        years = 0ll;
        dfs(1ll,0,60,1ll);
        cout<<ans<<endl;
    }
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

 



Guess you like

Origin www.cnblogs.com/qieqiemin/p/10958204.html