Title Link: Http://codeforces.com/problemset/problem/546/D
Test instructions: Input a,b,n=a! /b! , n is divided by how many times it becomes 1.
Analysis: Equivalent to the number of N to find the quality factor. That is, the number of digital factors from b+1 to a and how much.
#include <iostream>#include<cstring>#include<cstdio>using namespacestd;intv[5000005];//v[i] record I is a prime numberintprime[50000];//primes Tableintnum;intmini[5000005];//mini[i] Represents the minimum quality factor for I. intans[5000005];//ans[i] Indicates how many of the mass factors I have. intanswer[5000005];//answer[i] Indicates the total number of factors from 1 to Ivoidinit () {memset (V,0,sizeof(v)); Num=0; for(intI=2; i<=5000000; i++) Mini[i]=i; for(intI=2; i<=5000000; i++) { if(v[i]==0) {prime[++num]=i; } for(intj=1; j<=num&&i*prime[j]<=5000000; j + +) { intt=i*Prime[j]; V[t]=1; if(mini[t]>Prime[j]) mini[t]=Prime[j]; }} ans[2]=1; for(intI=3; i<=5000000; i++) {Ans[i]=ans[i/mini[i]]+1;//ans[i] for I divided by his minimum quality factor number plus 1} answer[1]=0; for(intI=2; i<=5000000; i++) {Answer[i]=answer[i-1]+Ans[i]; }}intMain () {intt,a,b; scanf ("%d",&t); Init (); while(t--) {scanf ("%d%d",&a,&b); printf ("%d\n", answer[a]-Answer[b]); } return 0;}
Codefo 546D. Soldier and number Game