1025: [SCOI2009] game time limit:1 Sec Memory limit:162 MB
submit:1533 solved:964
[Submit] [Status] [Discuss] Description
Windy learned a game. For n numbers from 1 to n, there are unique and different numbers of 1 to n corresponding to them. At first windy put the numbers in order 1,2,3,......,n write a line on the paper. Then write their corresponding numbers below the row. Then write their corresponding numbers under the new row. So repeatedly, until the sequence becomes 1,2,3,......,n again. For example: 1 2 3 4 5 6 The corresponding relationship is 1->2 2->3 3->1 4->5 5->4 6->6 windy operation as follows 1 2 3 4 5 6 2 3 1 5 4 6 3 1 2 4 5 6 1 2 3 5 4 6 2 3 1 4 5 6 3 1 2 5 4 6 1 2 3 4 5 6 At this point, we have a number of rows 1 to N, with 7 rows in the previous example. Now windy want to know the number of possible rows for all possible correspondence.
Input
Contains an integer, N.
Output
Contains an integer, possibly the number of rows.
Sample Input"Input Sample One"
3
"Input Sample Two"
10
Sample Output"Output Example One"
3
"Output Example II"
-HINT
"Data size and conventions"
100% data, satisfies 1 <= N <= 1000.
Source
Exercises
If some number of least common multiple is z, and Z=X1^P1*X2^P2...XM^PM, when they are x1^p1,x2^p2 ... When they are and are minimal. We try to minimize this, because when minimized, if and less than equal to N (less than 1), you can determine that z can be taken. Then, it can be found that we can enumerate the z by enumerating Xi^pi (factorization and its corresponding exponent) (and thus certainly not repeating), with the restriction being less than or equal to N. Then use Dp[k][s] to denote the number of cases of the smallest and the s of all z that are enumerated with the first k prime numbers. Headache, write a memory to be good.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= $+Ten, maxm= ++Ten, maxp=10000+Ten; One Long LongDP[MAXN][MAXM];intP[maxn],sz,n;BOOLPRI[MAXP]; A voidMakepriintN) { - intLIM=SQRT (n); memset (PRI,true,sizeof(PRI)); - for(intI=2; i<=lim;i++)if(Pri[i]) for(intJ=i*i;j<=n;j+=i) pri[j]=false; the for(intI=2; i<=n;i++)if(Pri[i]) P[++sz]=i;return; - } - Long LongCalcintKints) { - if(dp[k][s]>=0)returnDp[k][s];if(!k)returndp[k][s]=1; +Dp[k][s]=calc (K-1, s); - for(intTmp=p[k];tmp<=s;tmp*=p[k]) Dp[k][s]+=calc (K-1. Sotmp); + returnDp[k][s]; A } atInlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} - while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); - returnx*=Sig; - } inInlinevoidWriteLong Longx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; to intlen=0;Long Longbuf[ -]; while(x) buf[len++]=x%Ten, x/=Ten; + for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } the voidinit () { *n=read (); $MAKEPRI (n); memset (dp,-1,sizeof(DP));Panax Notoginseng Write (Calc (sz,n)); - return; the } + voidWork () { A return; the } + voidprint () { - return; $ } $ intMain () {init (); work ();p rint ();return 0;}
Bzoj 1025 [SCOI2009] Game