Title Link: http://lightoj.com/volume_showproblem.php?problem=1341
Test instructions
Given the integers a and B, the number of approximate pairs of a in the interval [B, a], the approximate pairs of a (e.g. [2, 3] and [3, 2] are the same pair).
Solution:
The main use of the formula:
An integer n can be expressed as a product of several prime numbers: n = p1^a1 * P2^A2*...*PM^AM;
The number of positive factors for n can be expressed as: num = (a1+1)* (a2+1) ... (am+1);
Code:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;Long LongN, M;Const intMAXN =1000010;BOOLNOTPRIME[MAXN];//value False for prime number, true for non-primeintPRIME[MAXN +1];voidGetprime () {memset(Notprime,false,sizeof(Notprime)); notprime[0] = notprime[1] =true;memset(Prime,0,sizeof(prime)); for(inti =2; I <= MAXN; i++) {if(!notprime[i]) prime[++prime[0]] = i; for(intj =1; J <= prime[0] && Prime[j] <= maxn/i; J + +) {notprime[prime[j] * i] =true;if(I%prime[j] = =0) Break; } }}intGetfactors () {intAns =1;intfatcnt =0;Long LongTMP = n;if(N/m < m)return 0; for(inti =1; Prime[i] <= tmp/prime[i]; i++) {intc =0; while(Tmp%prime[i] = =0) {C + +; TMP/= Prime[i]; } ans *= (c +1); }if(tmp >1) Ans <<=1; Ans >>=1; for(inti =1; I < m; i++)if(n% i = =0) ans--;returnAns;}intMain () {getprime ();intTscanf("%d", &t); for(intCases =1; Cases <= T; cases++) {scanf("%lld%lld", &n, &m);printf("Case%d:%d\n", cases, getfactors ()); }return 0;}
Lightoj 1341-aladdin and the Flying Carpet "composite decomposition"