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

Problem Description

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 kkk resistors with resistances R1,R2,...,RkR_1, R_2, ..., R_kR1​, R2​, ..., Rk​ in parallel and their combined resistance RRR:
R=11R1+1R2+⋯+1Rk.R=\frac{1}{\frac{1}{R_1}+\frac{1}{R_2}+\cdots+\frac{1}{R_k}}. R=R1​1​+R2​1​+⋯+Rk​1​1​.
Now you have nnn resistors, the iii-th of which has a resistance of rir_iri​ ohms with the equation
ri={∞if ican be divided by d2for some integers d≥2iotherwise. r_{i}=\left\{\begin{array}{ll}{\infty} & {\text {if } i \text { can be divided by } d^{2} \text {\; for some integers } d \geq 2} \\ {i} & {\text {otherwise. }}\end{array}\right. ri​={∞i​if i can be divided by d2for some integers d≥2otherwise. ​
You also have nnn selections, the iii-th of which is a set of resistors SiS_iSi​ such that
Si={the j-th resistor ∣jis a divisor of i}.S_{i}=\{\text { the } j \text { -th resistor } |\ j \text { 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 pq\frac{p}{q}qp​ of its resistance.

Input

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

For each test case, the only one line contains an integer nnn, where 1≤n≤101001 ≤ n ≤ 10^{100}1 ≤ n ≤ 10100.

Output

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

Example

Input

3
10
100
1000

Output

1/2
5/12
35/96

Problem solving report:

Description:如果iii是完全平方数(⩾4)(\geqslant 4)(⩾4)的倍数,那么iii号电阻的阻值为无穷大,否则为iii。
现在有编号为1∼n1\sim n1∼n的集合,每个集合包含若干个电阻,编号为iii的集合包含所有编号为iii的约数的电阻。求一个集合,使该集合内所有电阻的并联阻值最小。
Problem solving

  • 首先,对于一个电阻,如果它能改变总电阻,那么它的阻值不是无穷大,因此它的每个质因子最多被乘了一次。所以对于每个电阻的集合,它的编号的约数中,只有111、质因数、以及若干个不同质因数的积是有效的。另外,如果一个数的约数包含了若干个质因数,那么这个数的约数也必然包含这些质因数的积
  • 并联越多小电阻,总电阻越小,那就从最小的电阻开始选,越多越好,并且每个质因子只考虑一次。能选第iii个素数时,nnn应该不小于前iii个素数的乘积,这样才能保证前iii个素数在前iii个集合中同时出现在某一个集合内。
  • 选出包含前iii个素数的集合之后,该集合内的电阻应包括该iii个素数和该iii个素数所有组合出的乘积。设已经求出的电阻倒数之和为sumsumsum,下一个素数为ppp。则加入下一个电阻时有sum=sum∗(1+1/p)sum = sum*(1+1/p)sum=sum∗(1+1/p),这样就可以很顺利的求出最终结果的倒数。因为要输出成分数形式,所以在递推的过程要分别保存分子和分母,最后输出前记得约分。

Accepted Code:

/* * @Author: lzyws739307453 * @Language: C++ */
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
bool isp[MAXN];
char str[MAXN];
int pre[MAXN], cnt;
struct edge {int p[MAXN], size;edge() {//初始化size = 0;memset(p, 0, sizeof(p));}int cmp(edge b) {//高精度比大小if (size > b.size) return 1;if (size < b.size) return -1;for (int i = size - 1; ~i; i--) {if (p[i] > b.p[i]) return 1;if (p[i] < b.p[i]) return -1;}return 0;}edge mul(int b) {//高精度*单精度edge c;int t = 0;for (int i = 0; i < size || t; i++) {if (i < size)t += p[i] * b;c.p[c.size++] = t % 10;t /= 10;}return c;}edge Mul(edge b) {//高精度*高精度edge c;int t = 0;for (int i = 0; i < size; i++) {for (int j = 0; j < b.size; j++) {t += p[i] * b.p[j];c.p[i + j] += t % 10;t /= 10;}}c.size = size + b.size - 1;while (t) {c.p[c.size++] = t % 10;t /= 10;}return c;}edge Sub(edge b) {//高精度-高精度edge c;int t = 0;for (int i = 0; i < size; i++) {t = p[i] - t;if (i < b.size)t -= b.p[i];c.p[i] = (t + 10) % 10;t = t < 0;}c.size = size;while (c.size > 1 && !c.p[c.size - 1]) --c.size;return c;}edge Div(edge b) {//高精度/高精度edge quo, rem = *this;quo.size = 1, quo.p[0] = 0;if (rem.cmp(b) < 0)return quo;quo.size = rem.size - b.size;for (int i = rem.size - 1; ~i; i--) {if (i >= quo.size) b.p[i] = b.p[i - quo.size];else b.p[i] = 0;}b.size = rem.size;for (int i = 0; i <= quo.size; i++) {while (rem.cmp(b) >= 0) {rem = rem.Sub(b);quo.p[quo.size - i]++;}for (int j = 0; j < b.size - 1; j++)b.p[j] = b.p[j + 1];--b.size;}++quo.size;while (quo.size > 1 && !quo.p[quo.size - 1]) --quo.size;return quo;}edge Mod(edge b) {//高精度%高精度edge quo, rem = *this;quo.size = 1, quo.p[0] = 0;if (rem.cmp(b) < 0)return rem;quo.size = rem.size - b.size;for (int i = rem.size - 1; ~i; i--) {if (i >= quo.size) b.p[i] = b.p[i - quo.size];else b.p[i] = 0;}++quo.size;b.size = rem.size;for (int i = 0; i < quo.size; i++) {while (rem.cmp(b) >= 0) {rem = rem.Sub(b);quo.p[quo.size - i - 1]++;}for (int j = 0; j < b.size - 1; j++)b.p[j] = b.p[j + 1];--b.size;}while (rem.size > 1 && !rem.p[rem.size - 1]) --rem.size;return rem;}edge gcd(edge b) {//高精度取最大公约数if (!b.p[0] && b.size == 1)return *this;return b.gcd(Mod(b));}
};
void Get_prime(int n) {//质数筛cnt = 0;for (int i = 2; i < n; i++) {if (!isp[i])pre[cnt++] = i;for (int j = 0; i * pre[j] < n && j < cnt; j++) {isp[i * pre[j]] = true;if (!(i % pre[j]))break;}}
}
int main() {int t;Get_prime(300);scanf("%d", &t);while (t--) {edge m, Mol, Den;scanf("%s", str);int len = strlen(str);for (int i = 0; i < len; i++)m.p[len - i - 1] = str[i] - '0';m.size = len;Mol.size = 1, Mol.p[0] = 1;Den.size = 1, Den.p[0] = 1;for (int i = 0; Mol.mul(pre[i]).cmp(m) <= 0; i++) {Mol = Mol.mul(pre[i]);Den = Den.mul(pre[i] + 1);}edge Gcd = Den.gcd(Mol);Mol = Mol.Div(Gcd), Den = Den.Div(Gcd);for (int i = Mol.size - 1; ~i; i--)printf("%d", Mol.p[i]);printf("/");for (int i = Den.size - 1; ~i; i--)printf("%d", Den.p[i]);printf("\n");}return 0;
}

CodeForces - [ACM-ICPC Jiaozuo Onsite D]Resistors in Parallel(高精度C++)相关推荐

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

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

  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 ...

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

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

  4. 2019年安徽大学ACM/ICPC实验室新生赛题解

    本文仅作个人收藏学习使用 题目及解析来源牛客竞赛网 //作者:王清楚 //链接:https://ac.nowcoder.com/discuss/351408?type=101&order=0& ...

  5. ACM / ICPC 在线OJ(Online judge)

    1. codeforces    codeforces (这个网站每天会有比赛,一起打CF吧!) http://codeforces.com/problemset 2.  topcoder:  htt ...

  6. ACM/ICPC 比赛生涯总结+经验分享

    ACM/ICPC 比赛生涯总结+经验分享 1.获奖经历 时间 比赛 奖励 大一下 ACM陕西省赛 打铁 大一下 CCCC 团队二等奖 大二下 ACM/ICPC全国邀请赛 银奖 大二下 CCCC 团队特 ...

  7. 2019 ACM - ICPC 上海网络赛 E. Counting Sequences II (指数型生成函数)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

  8. 2019 ACM - ICPC 西安邀请赛 B. Product (杜教筛) 简单数论(bushi)

    G.(2019 ACM/ICPC 全国邀请赛(西安)B) Product Weblink https://nanti.jisuanke.com/t/39269 Problem && S ...

  9. 解题报告(一)F、(2018 ACM - ICPC shenyang I)Distance Between Sweethearts(数学期望 + 乘法原理 + FWT)(4.5)

    繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我写的超高质量题解和代码,题目难度不一定按照题号排序,我会在每道题后面加上题目难度指数(1∼51 \sim 51∼5),以模板题难度 11 ...

最新文章

  1. 企业文件服务器资源管理方案
  2. jquery.cookie 使用方法
  3. 复习.net/c#时的小文章之万年草稿版 (全是基础概念,请懂的人绕行)
  4. java activemq jmx_通过JMX 获取Activemq 队列信息
  5. JS 构造图片Image对象
  6. SQL Server更新某一列中多个字典码对应内容(sql示例)
  7. 云服务器如何链接本地打印机_利用FileZilla搭建云服务器FTP服务端和本地客户端...
  8. 网上购物安全防范很重要
  9. Linux strace命令 一
  10. Dijkstra 路径规划 C#
  11. 魅族插了卡显示无服务器,魅族手机SD卡无法读取怎么办解决方案
  12. plc和变频器通讯接线图详解
  13. HDU - Shaolin(STL)
  14. 改善网页性能的5种方法
  15. Epub电子书的格式(二)
  16. 如何在官网验证cka证书
  17. 大学生学剪辑蒙太奇技巧怎么用?
  18. video.js播放rtmp直播源和hls直播源
  19. C#完美实现打开笔记本电脑摄像头
  20. 服务器系统通用串行总线控制器,win7系统usb设备不能用通用串行总线控制器无法启动的解决方法...

热门文章

  1. sql 创建表,批量插入数据
  2. Fabric 节点类型&交易流程
  3. 干货分享——产品经理必备的技能:专业技能和软技能。
  4. 读书笔记--《软技能-代码之外的生存指南》
  5. 怎么理解预训练模型?
  6. L1D1:嵌入式Linux C语言开发工具及基础命令
  7. php中的isset函数
  8. 单独按戴尔笔记本f11键和f12键无法调节亮度了怎么办?用(Fn+F11键或者Fn+F12键就好)
  9. android实现新闻内容显示功能,Android开发实现自定义新闻加载页面功能实例
  10. 开源节流系列之工程施工篇