POJ 3421 X-factor Chains

Source: Internet
Author: User
Tags define local cmath

This chain is multiplied by a factor. Because of the N<2^20,SQRT (n) decomposition factor, the same factor is taken in a relative order.

#include <cstdio>#include<iostream>#include<string>#include<cstring>#include<queue>#include<vector>#include<stack>#include<vector>#include<map>#include<Set>#include<algorithm>#include<cmath>//#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;#definePB push_backConst intMAXN =1<< -; ll fac[ +];voidCALFAC (intn = -) {fac[0] =1;  for(inti =1; I <= N; i++) {Fac[i]= fac[i-1]*i; }}intPrimedecompose (intN,ll &Div) {    intRe =0; div =1;  for(inti =2; I*i <= N; i++){        intCNT =0;  while(n% i = =0) {n/=i; CNT++; Re++; }        if(CNT) Div *=fac[cnt]; }    if(n>1) re++; returnre;}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifCALFAC (); intX;  while(~SCANF ("%d",&X))        {ll div; intLen =Primedecompose (X,DIV); LL SHC= fac[len]/Div; printf ("%d%i64d\n", LEN,SHC); }    return 0;}

I tried to speed up the judgment with a pre-screened prime number of sqrt (n), but the result was 26ms slower.

#include <cstdio>#include<iostream>#include<string>#include<cstring>#include<queue>#include<vector>#include<stack>#include<vector>#include<map>#include<Set>#include<algorithm>#include<cmath>//#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;#definePB push_backConst intMAXN =1<< -;Const intSqrn =1<<Ten;//(int) sqrt (maxn+0.5); + 5Const intPrmsz = (1<<8)+5;//(sqrn>>2) + 5BOOLIsnot[sqrn];intPrm[prmsz], tot;voidSeive (intn = sqrn)//sqrt (sqrt (MAXN)){    intm = sqrt (n+0.5); isnot[0] = isnot[1] =true;  for(inti =2; I <= m; i++){        if(!Isnot[i]) for(intj = i*i; J <= N; J + =i) {Isnot[j]=true; }    }     for(inti =2; I <= N; i++){        if(!isnot[i])//PRM.PB (i);prm[tot++] =i; }}ll fac[ +];voidCALFAC (intn = -) {fac[0] =1;  for(inti =1; I <= N; i++) {Fac[i]= fac[i-1]*i; }}inlineintPrimedecompose (intN,ll &Div) {    intRe =0; div =1;  for(inti =0; I < tot && prm[i] <= N; i++){        intp = prm[i], cnt =0;  while(n% p = =0) {n/=p; CNT++; Re++; }        if(CNT) Div *=fac[cnt]; }    if(n>1) re++; returnre;}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifseive ();    CALFAC (); intX;  while(~SCANF ("%d",&X))        {ll div; intLen =Primedecompose (X,DIV); LL SHC= fac[len]/Div; printf ("%d%i64d\n", LEN,SHC); }    return 0;}

POJ 3421 X-factor Chains

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.