E. Resistors in Parallel
E. Resistors in Parallel
[link](Problem - E - Codeforces)
题意
给你n个电阻,如果第i个电阻可以被一个大于1的完全平方数整除,他的阻值就是无穷,否则就是i。现在给你n个选择,每一个选择包含一个电阻集合,该集合由所有i的因数j,第j个电阻构成。让你选择其中一个集合,要求这些电阻并起来最小。
题解
并联的公式是 R = 1 1 R 1 + 1 R 2 + . . . + 1 R k R=\frac {1}{\frac 1{R_1} + \frac 1{R_2}+...+ \frac 1{R_k}} R=R11+R21+...+Rk11,我们要并联后的尽可能小,所以要分母尽可能大。第i个操作的集合所包含的电阻都是i的约数,任意一个数都可以被拆成一些质数的乘积,因为所有有平方因子的都是INF,所以对于重复的质因子是没有贡献的,只是和不同质因子有关。对于每一个质因子选于不选,构成的约数集合。化简以后分子就是前n个素数的乘积,分母是所有的约数相加,也就相当于一个二项式,也就是前n个素数,每一个素数加1然后相乘。
由于数据范围太大,所以用java的大数类更为方便。
Code
import java.math.BigInteger;
import java.util.Scanner;public class Main {static int []a = new int[1005];static int N = 200005;static long []primes = new long[N];static long cnt = 0;static int []ok = new int[N];public static void main(String[] args) {Scanner in = new Scanner(System.in);primes[0] = 0;ok[0] = 1;ok[1] = 1;get_prime();int T = in.nextInt();while ((int) T -- > 0) {BigInteger n = in.nextBigInteger();BigInteger sum1 = new BigInteger("1");BigInteger sum2 = new BigInteger("1");int i = 0;while (true) {if (sum1.multiply(new BigInteger(String.valueOf(primes[i]))).compareTo(n) <= 0) {sum1 = sum1.multiply(new BigInteger(String.valueOf(primes[i])));sum2 = sum2.multiply(new BigInteger(String.valueOf(primes[i] + 1))); }else break;i ++;}BigInteger d = Gcd(sum1, sum2);sum1 = sum1.divide(d);sum2 = sum2.divide(d);System.out.println(sum1+"/"+sum2);}}static BigInteger Gcd(BigInteger a, BigInteger b) {if (b.compareTo(new BigInteger("0")) == 0) return a;else return Gcd(b, a.mod(b));}static void get_prime() {for (long i = 2; i < N; i ++ ) {if (ok[(int)i] == 0) primes[(int)cnt ++] = i;for (long j = 0; primes[(int)j] < N / i; j ++ ) {ok[(int)(primes[(int)j] * i)] = 1;if ((i % primes[(int)(j)]) == 0) break;}}}
}
E. Resistors in Parallel相关推荐
- 2018ACM-ICPC焦作站E题Resistors in Parallel
Resistors in Parallel 题目: ACM-ICPC Jiaozuo Onsite 2018 题解:因为题目数据范围很大,所以猜测应该是一个区间一个固定的最小值.问题转换成了如何求某个 ...
- 2018焦作ICPC E. Resistors in Parallel(打表+大数)
E. Resistors in Parallel 题意: 图1: 图2 图3: 选择n以内的一个i,使得Si最大,S_i的值就是说i的所有因子作为下标j,对所有r_j(计算方式见图1)进行图2中的运算 ...
- 2018 焦作 onsite E - Resistors in Parallel(数学或规律+大数)
题目链接:http://codeforces.com/gym/102028/problem/EE. Resistors in Parallel time limit per test 2.0 s me ...
- 2018焦作ICPC E - Resistors in Parallel(规律+Java大数)
2018焦作ICPC E - Resistors in Parallel题目链接 Time limit 2000 ms Memory limit 1048576 kB In this physic ...
- python笔记之1-简单读入+循环、判断+数组+函数调用+题目Resistors in Parallel(18焦作)
....本来博主想一心一意搞算法和C++的,但今天的大数用C++写真的...心态爆炸,然后学了一波python...多路周折终于A了这题 python的语言在有了c语言的基础上其实还挺好学的...虽然 ...
- 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 ...
- ACM-ICPC Jiaozuo Onsite 2018 Resistors in Parallel (思维+java大数+找规律)
题目来源 ACM-ICPC Jiaozuo Onsite 2018 题目粘贴过来有点变化,既然来了肯定见过原题~~嘻嘻~~ In this physics problem, what we are c ...
- Resistors in Parallel(找规律+大数)
题意:https://codeforces.com/group/ikIh7rsWAl/contest/254825/problem/E 给你一个n,计算n / Sigma(1~n)的d(是n的只出现一 ...
- 2018 ICPC 焦作区域赛 Resistors in Parallel(找规律+大数)
传送门 题目大意 给出电阻的并联公式,规定一个含有平方因子的数的1R=0\frac{1}{R}=0R1=0.定义一个数的阻值为其所有的因子阻值并联求出的结果,问nnn以内并联后的最大的阻值是多少,输 ...
最新文章
- XAMPP 配置虚拟域名/localhost重定向
- 【错误记录】Android Studio 编译报错 ( Error:Connection timed out: connect | 更新配置依赖仓库方式 )
- 迭代最近点算法 Iterative Closest Points
- 【Python】Python的类和对象(长文系列第⑤篇)
- 解题:USACO15JAN Grass Cownoisseur
- 学院后勤报修系统php_如何有效提升医院医疗设备故障报修问题?
- 内存管理(C语言中malloc和free的用法)
- Linux 中的旧扣簧键盘(Bucklespring 键盘)声音
- MAC 安装JDK(附JDK下载地址)
- java 行政区划编号_行政区划 | Java Service SDK | 开发支持 | 四维地图开放平台
- 服务器发电子邮件,服务器拒绝接受发件人的电子邮件地址,这封邮件无法发送...
- oracle 如何考试,oracle考试怎么报名
- matlab 读取dbf文件
- 企业级docker安装kong,konga实战
- 我与我的专业计算机网络作文,我与网络的故事作文600字
- 常用的学生、课程、成绩、教师表的查询
- div设置下拉滚动条以及翻滚到底部
- php mpt文件,skyline制作mpt
- 毕设 房地产客服管理系统论文
- 【不做手机控】如何屏蔽微信朋友圈?
热门文章
- js验证前台验证用户名只能是汉字
- http://code4app.com/ios/SCCaptureCamera/530ad8cccb7e84ba4d8b630e
- 《长安十二时辰(中亚,套装共2册)》马伯庸 (作者)电子书网盘下载
- Elastic: IllegalStateException: availableProcessors is already set to [8], rejecting [8]
- linux 带ifdef运行程序_Linux内核如何装载和启动一个可执行程序
- linux报错Permission denied
- 理解总结5G时代音乐领域前瞻
- 当技术重塑健身产业,AI有可能胜过人类教练吗?
- 90后情侣3年攒100万裸辞飞荷兰
- 用Python将你的微信打造成机器人