Find Solutions (least factor decomposition)

Source: Internet
Author: User

Description


Find Solutions

Look at the following equation:

C = AB -+ 1

Now given the valueC, How many possible values of andAAndBAre there (AAndBMust be positive integers )? That is you will have to find the number of Pairs(A,B)Which satisfies the above equation.

Input

The input file contains around 3000 line of input. Each line contains an IntegersN(0 <N1014). ThisNActually denotes the valueC. A line containing a single zero terminates the input. This line shoshould not be processed.

Output

For each line of input produce one line of output. This line contains two integers. First integer denotes the valueCAnd the second integer denotes the number of pair of valuesAAndBThat satisfies the above equation, given the valueC.

Sample Input
 
10204000
Sample output
1020 8400 2 Question: Finding equations is all the possibilities of C

Train of Thought: C = A ? B ? A + B 2 + 1 After factorization 4 ? C ? 3 = ( 2 ? A ? 1 ) ? ( 2 ? B ? 1 )

Therefore, this question can be converted to the composition of the factor of 4 * C-3, after finding the prime number of all the factors, is to use the partition method to split f [I] into two, is multiplied by F [I] + 1.

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> typedef long ll; using namespace STD; const int maxn = 22000000; int f [maxn], B [maxn]; int LP, P [maxn> 3], PRI [maxn]; void Init () {// pri [] minimum factor Lp = 0; For (INT I = 2; I <maxn; I ++) {If (! PRI [I]) P [LP ++] = pri [I] = I; for (Int J = 0; j <LP & I * P [J] <maxn; j ++) {pri [I * P [J] = P [J]; if (I % P [J] = 0) Break ;}}} void CAL (ll n, ll & L, int B [], int f []) {ll TMP, I = 0; L = 0; while (n> 1) {If (n <maxn) TMP = pri [N]; else {TMP = N; (; I <LP & N/P [I]> = P [I]; I ++) if (N % P [I] = 0) {TMP = P [I]; break;} f [l] = 0; while (N % TMP = 0) {n/= TMP; f [l] ++;} B [L ++] = TMP ;}} int main () {ll n, l; I Nit (); While (scanf ("% LLD", & N )! = EOF & N) {CAL (4 * N-3, L, B, F); LL sum = 1; for (INT I = 0; I <L; I ++) sum * = f [I] + 1; printf ("% LLD \ n", N, sum);} return 0 ;}


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.