题目链接: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 BigInteger[110];static BigInteger[] fz = new BigInteger[110];static BigInteger[] fm = new BigInteger[110];//gcd public static BigInteger gcd(BigInteger a, BigInteger b){if(b.compareTo(BigInteger.ZERO)==0) // 若小于返回-1,等于则返回0,大于则返回1return a;else return gcd(b,a.mod(b));}static BigInteger Gcd;public static void getPrime() // 素数筛,注意静态函数只能调用静态变量{num[0]=BigInteger.valueOf(1);fz[0]=BigInteger.valueOf(1);fm[0]=BigInteger.valueOf(1);for(int i=2;i<N;i++){if(prime[0]>100) break;if(prime[i]==0){prime[++prime[0]]=i;num[prime[0]]=num[prime[0]-1].multiply(BigInteger.valueOf(i));fz[prime[0]]=fz[prime[0]-1].multiply(BigInteger.valueOf(i));fm[prime[0]]=fm[prime[0]-1].multiply(BigInteger.valueOf(i+1));Gcd=gcd(fz[prime[0]],fm[prime[0]]);fz[prime[0]]= fz[prime[0]].divide(Gcd);fm[prime[0]]= fm[prime[0]].divide(Gcd);}for(int j=1;j<=prime[0]&&i*prime[j]<N;j++){prime[i*prime[j]]=1;if(i%prime[j]==0)break;}}}public static void main(String[] args){getPrime();Scanner sc = new Scanner(System.in);int t;// for(int i=0;i<2;i++)// {// System.out.println(num[i]);// }BigInteger n;t=sc.nextInt();while(t--!=0){n=sc.nextBigInteger();int idx=0;while(n.compareTo(num[idx])>=0)//返回第一个大于n的位置idx{idx++;}if(idx==1)System.out.println("1/1");else{System.out.println(fz[idx-1]+"/"+fm[idx-1]);}}}
}

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

  1. 2018焦作ICPC E. Resistors in Parallel(打表+大数)

    E. Resistors in Parallel 题意: 图1: 图2 图3: 选择n以内的一个i,使得Si最大,S_i的值就是说i的所有因子作为下标j,对所有r_j(计算方式见图1)进行图2中的运算 ...

  2. 2018 ICPC 焦作区域赛 Resistors in Parallel(找规律+大数)

    传送门 题目大意 给出电阻的并联公式,规定一个含有平方因子的数的1R=0\frac{1}{R}=0R1​=0.定义一个数的阻值为其所有的因子阻值并联求出的结果,问nnn以内并联后的最大的阻值是多少,输 ...

  3. 2018焦作ICPC E - Resistors in Parallel(规律+Java大数)

    2018焦作ICPC E - Resistors in Parallel题目链接 Time limit  2000 ms Memory limit  1048576 kB In this physic ...

  4. 【2018焦作-E】Resistors in Parallel(思维+大数)

    题目链接 思路: 思考一下会发现选择质因子越多的且越小的会使得结果更小,因此预处理前100的质因子,询问直接查询处理数组.需要写大数 ac代码: import java.util.Scanner; i ...

  5. Resistors in Parallel(找规律+大数)

    题意:https://codeforces.com/group/ikIh7rsWAl/contest/254825/problem/E 给你一个n,计算n / Sigma(1~n)的d(是n的只出现一 ...

  6. ACM-ICPC Jiaozuo Onsite 2018 Resistors in Parallel (思维+java大数+找规律)

    题目来源 ACM-ICPC Jiaozuo Onsite 2018 题目粘贴过来有点变化,既然来了肯定见过原题~~嘻嘻~~ In this physics problem, what we are c ...

  7. CodeForces - [ACM-ICPC Jiaozuo Onsite D]Resistors in Parallel(高精度C++)

    题目链接:https://codeforces.com/gym/102028/problem/E Time limit: 2.0 s Memory limit: 1024 MB Problem Des ...

  8. 2018ACM-ICPC焦作站E题Resistors in Parallel

    Resistors in Parallel 题目: ACM-ICPC Jiaozuo Onsite 2018 题解:因为题目数据范围很大,所以猜测应该是一个区间一个固定的最小值.问题转换成了如何求某个 ...

  9. python笔记之1-简单读入+循环、判断+数组+函数调用+题目Resistors in Parallel(18焦作)

    ....本来博主想一心一意搞算法和C++的,但今天的大数用C++写真的...心态爆炸,然后学了一波python...多路周折终于A了这题 python的语言在有了c语言的基础上其实还挺好学的...虽然 ...

最新文章

  1. linux进程地址空间没有段,Linux进程的虚拟地址空间
  2. 才做三个月的新业务,为何唐岩对陌陌直播寄予厚望
  3. k8s使用volume将ConfigMap作为文件或目录直接挂载_从零开始入门 K8s | 如何实现应用配置管理?...
  4. ICLR 2021 | 显存不够?不妨抛弃端到端训练
  5. 同步规则和happen-before规则
  6. ORA-07445:[SIGFPE] [Integer divide by zero]内部错误一例
  7. let 只能在严格模式下吗_LET的完整形式是什么?
  8. SQLServer 2008 已成功与服务器建立连接,但是在登录前的握手期间发生错误。 (provider: SSL Provider, error: 0 - 等待的操作过时。...
  9. 关于计算机博弈的开源项目
  10. Router Configuration5
  11. 微服务把多个模块服务 聚合成一个服务
  12. 午休,要有午休床,也要有毛毯
  13. 微信支付——委托代扣介绍
  14. SAP ABAP ALV 布局 特定用户 及缺省设置控制
  15. uniapp 查看图片点击放大预览图片 单张 多张
  16. html在线考试系统论文,在线考试系统
  17. 高频引力波数值计算matlab,李刚李莉张雏黄敬霞受热变形及系统优化分析J光.doc...
  18. 读书笔记 摘自:《为什么精英都是时间控》
  19. 基于Android课堂学习系统的文献综述
  20. QQ个性域名邮箱(免费企业邮箱)快速申请

热门文章

  1. Linux下自动重启系统
  2. uniapp引入openLayers天地图
  3. 查看、修改数据库和表的编码格式
  4. 饥荒联机版服务器显示错误,搭建服务器启动出错
  5. 2017年10月WEB前端开发实习生面试题总结
  6. 智能网联汽车信息安全学术研究现状
  7. 克隆linux系统之后如何配置网络ip
  8. 微信公众号js-sdk定位 获取经纬度和详细位置
  9. ARM S5PV210 X210 刷机教程总结
  10. Flask03_路由传参