题目来源
题目粘贴过来有点变化,既然来了肯定见过原题~~嘻嘻~~
In this physics problem, what we are concerned about are only resistors. If you are poor at physics, do not worry, since solving this problem does not require you to have advanced abilities in physics.
Resistors are said to be connected together in parallel when both of their terminals are respectively connected to each terminal of the other resistors.
We have the following parallel resistor equation for kk resistors with resistances R_1, R_2, \cdots, R_kR1,R2,⋯,Rk in parallel and their combined resistance RR:
\displaystyle R = \frac{1}{\frac{1}{R_1} + \frac{1}{R_2} + \cdots + \frac{1}{R_k}}.R=R11+R21+⋯+Rk11.
Now you have nn resistors, the ii-th of which has a resistance of r_iri ohms with the equation
\displaystyle r_i = \begin{cases} \infty & \text{if $i$ can be divided by $d^2$ for some integers $d\ge 2$,}\\ i & \text{otherwise.} \end{cases}ri={∞iif i can be divided by d2 for some integers d≥2,otherwise.
You also have nn selections, the ii-th of which is a set of resistors S_iSi such that
\displaystyle S_i = \{\text{the $j$-th resistor} \mid \text{$j$ is a divisor of $i$}\}.Si={the j-th resistor∣j is a divisor of i}.
Please find a selection in which the resistors form a parallel resistor with the minimum resistance and output the reduced fraction \frac{p}{q}qp of its resistance.
Input
The input contains several test cases, and the first line contains a positive integer TT indicating the number of test cases which is up to 100100.
For each test case, the only one line contains an integer nn, where 1 \leq n \leq 10^{100}1≤n≤10100.
Output
For each test case, output a line containing a reduced fraction of the form \text{p/q}p/q indicating the minimum possible resistance, where \text{p}p and \text{q}q should be positive numbers that are coprime.
样例输入复制
3 10 100 1000
样例输出复制
1/2 5/12 35/96
题意:给出一个n,找出从1~n最小的并联电阻。就是找1~n每个数的因子,注意如果因子能被平方数整除,那这个因子就是无穷大,然后根据公式计算并联电阻,找到1~n中并联电阻最小的一个。
题解:因为数据很大所以需要,java大数,详细的过程请看代码:
import java.util.*;
import java.math.*;
public class Main {
static Scanner cin = new Scanner (System.in);
static boolean [] vis = new boolean [521];
static BigInteger [] dp = new BigInteger[521];
static int [] pr = new int [521];
static int cnt=0;
static void getpr() {//欧拉筛 找素数
vis[0]=vis[1]=true;
for (int i = 2; i <= 520;i++) {//我找到520,可以少找一点,只要使所有的素数乘起来大于10^100就好
if(!vis[i]) pr[++cnt]=i;
for (int j = 1; j <= cnt && i*pr[j] <= 520;j++) {
vis[i*pr[j]]=true;
if(i%pr[j]==0) break;
}
}
}
public static void main(String[] args) {
getpr();
int t=cin.nextInt();
while(t-->0) {
int k;
BigInteger sum = cin.nextBigInteger();
BigInteger ans = BigInteger.ONE;
dp[0]=BigInteger.ONE;
for (k = 1;ans.multiply(BigInteger.valueOf(pr[k])).compareTo(sum)<=0;k++) {
ans=ans.multiply(BigInteger.valueOf(pr[k]));
}//找规律
k--;
for (int i = 1; i <= k;i++) {
dp[i]=dp[i-1].add(dp[i-1].multiply(BigInteger.valueOf(pr[i])));
}//找规律
BigInteger gcd=ans.gcd(dp[k]);
System.out.println(ans.divide(gcd)+"/"+dp[k].divide(gcd));//直接除以最大公因数
}
}
}