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