HDU1299 & SPOJ-KPEQU (number of solutions for finding a factor)
Question:
The number of solutions for Equation 1/x + 1/y = 1/n is 1/3 + 1/2 and 1/2 + 1/3.
Analysis:
1/x + 1/y = 1/n set y = n + k;
=> 1/x + 1/(n + k) = 1/n;
==> X = n ^ 2/k + n;
Because x is an integer, k is the approximate number of n ^ 2.
The Code is as follows:
# Include
# Include
# Include
# Include using namespace std; const int maxn = 1e7 + 10; typedef long LL; int p [maxn/10], cnt; bool vis [maxn]; int fac [1000], tot; void init () {cnt = 0; memset (vis, 0, sizeof (vis); for (int I = 2; I
1) fac [tot ++] = 1; LL ans = 1; for (int I = 0; I
Link: SPOJ-KPEQU Portal
Question:
Similar to the above, n is replaced by n !, Therefore, high precision and n are required! Prime factor decomposition
import java.math.BigInteger;import java.util.Scanner;public class Main {static int cnt ;static int[] pri =new int[10010];static boolean[] vis = new boolean[10010];public static void init(){cnt=0;for(int i=0;i<10010;i++) vis[i] = false;for(int i=2;i<10010;i++){if(!vis[i]){pri[cnt++]=i;for(int j=i+i;j<10010;j+=i) vis[j]=true;}}}public static int calc(int n,int p){if(n