Lightoj 1341-aladdin and the Flying Carpet "composite decomposition"

Source: Internet
Author: User

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"

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.