2018 焦作 onsite E - Resistors in Parallel(数学或规律+大数)

该物理问题涉及将电阻并联连接,并给出并联电阻的公式。输入包含多个测试用例,每个用例给出一个正整数n,表示有n个电阻。任务是找到一组并联后具有最小电阻的电阻组合,输出其简化后的分数形式。示例显示了对于不同n值的输出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://codeforces.com/gym/102028/problem/EE. Resistors in Parallel

time limit per test
2.0 s
memory limit per test
1024 MB
input
standard input
output
standard output

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 k resistors with resistances R1, R2, …, Rk in parallel and their combined resistance R:

Now you have n resistors, the i-th of which has a resistance of ri ohms with the equation

You also have n selections, the i-th of which is a set of resistors Si such that

Please find a selection in which the resistors form a parallel resistor with the minimum resistance and output the reduced fraction of its resistance.
Input

The input contains several test cases, and the first line contains a positive integer T indicating the number of test cases which is up to 100.

For each test case, the only one line contains an integer n, where 1 ≤ n ≤ 10100.
Output

For each test case, output a line containing a reduced fraction of the form p/q indicating the minimum possible resistance, where p and q should be positive numbers that are coprime.
Example
Input
Copy

3
10
100
1000

Output
Copy

1/2
5/12
35/96

解析:

前i个素数相乘的积就是最大值所在的位置,得大数,然鹅java忘了;
好久没写java,啥都不记得了

code:

/* 
BigInteger.valueOf(s)  // 将参数转化为指定类型,这里是BigInteger 
b.compareTo(BigInteger.ZERO) // 若小于返回-1,等于则返回0,大于则返回1  ;BigInteger.ZERO是大数的0
Scanner sc=new Scanner(System.in);
BigInteger big1=sc.nextBigInteger();
BigInteger big2=sc.nextBigInteger();
System.out.println("加法操作:" + big1.add(big2));
System.out.println("减法操作:" + big1.subtract(big2));
System.out.println("乘法操作:" + big1.multiply(big2));
System.out.println("除法操作:" + big1.divide(big2));
BigInteger result[] = big1.divideAndRemainder(big2);
System.out.println("相除后的商是:" + result[0]);
System.out.println("相除后的余数是:" + result[1]);
*/

import java.math.BigInteger;
import java.util.Scanner;



public class Main{
   
	
	static int N= 100005;
	static int[] prime = new int[N];
	
	static BigInteger[] num = new 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值