icpc2018-焦作-E Resistors in Parallel-数论+大数
http://codeforces.com/gym/102028/problem/E
定义n种电阻,阻值r[i]={ inf | i%d2==0 && d>1 , i | else}
然后定义n种电阻集合,S[i]={ j | i%j==0} , 现在询问给定n找出一个集合Si,使得将Si内的电阻并联之后电阻值最小,输出最简分数格式。
考虑将一个数质因数分解后 x=p1a1p2a2...pnan,由于题目中i%d^2==0时电阻是无穷大,1/ri 就是零了不必再考虑,也就是说只用考虑x的不同因子的数量和大小即可,当大小尽可能的小,数量尽可能的多时答案就尽量的大。我们就想办法构造一个不大于n的形如 2*3*5*....*pmax的数,那么答案就是∏(1+1/pi)。由于n的范围很大而我java已经忘光,手写了个大数水过。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<deque>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<cstdlib>
#include<ctype.h>
#include<ctime>
#include<functional>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define debug puts("debug")
#define mid ((L+R)>>1)
#define lc (id<<1)
#define rc (id<<1|1)
const int maxn=;
const int maxm=;
const double PI=acos(-1.0);
const double eps=1e-;
const LL mod=1e9+;
LL gcd(LL a,LL b){return b==?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL qpow(LL a,LL b,LL c){LL r=; for(;b;b>>=,a=a*a%c)if(b&)r=r*a%c;return r;}
struct Edge{int v,w,next;}; template<class T>
ostream & operator<<(ostream &out,vector<T>&v){
for(auto x:v)cout<<x<<' ';
return out;
}
void read(LL &n){
n=; char c=getchar();
while(c<''||c>'')c=getchar();
while(c>=''&&c<='') n=(n<<)+(n<<)+(c-''),c=getchar();
} const int MAX=;
vector<int>prime;
bool is[];
void init(){
is[]=is[]=;
for(int i=;i<=MAX;++i){
if(!is[i])prime.pb(i);
for(auto v:prime){
if(i*v>MAX)break;
is[i*v]=;
if(i%v==)break;
}
}
}
struct Bign{
int a[];
Bign(){memset(a,,sizeof(a));}
Bign(char *s){
memset(a,,sizeof(a));
a[]=strlen(s);
for(int i=;i<a[];i++)a[a[]-i]=s[i]-'';
}
Bign &operator *(int x){
for(int i=;i<=a[];++i)a[i]*=x;
for(int i=;i<=a[];++i){
if(a[i]>){
a[i+]+=a[i]/,a[i]%=;
if(a[a[]+]) a[]++;
}
}
return *this;
}
bool operator>(Bign &A){
if(a[]!=A.a[]) return a[]>A.a[];
for(int i=a[];i>=;--i){
if(a[i]>A.a[i])return ;
else if(a[i]<A.a[i]) return ;
}
return ;
}
}AA;
ostream &operator<<(ostream &out,Bign &A){
for(int i=A.a[];i>=;--i)out<<A.a[i];
return out;
}
void AC(){ char str[],one[]="";
scanf("%s",str);
Bign A(str);
Bign B(one);
int n;
for(n=;n<prime.size();++n){
//cout<<prime[n]<<' '<<B<<' '<<A<<' '<<(B>A)<<endl;
B=B*prime[n];
//cout<<"n="<<n<<endl;
if(B>A)break;
}
vector<LL>fz,fm;
fz.pb(),fm.pb();
for(int i=;i<n;++i){
//LL fz1=1+prime[i],fm1=prime[i];
//fz*=fz1,fm*=fm1;
fz.pb(+prime[i]);
fm.pb(prime[i]);
}
for(int i=;i<fz.size();++i){
for(int j=;j<fm.size();++j){
LL gg=gcd(fz[i],fm[j]);
fz[i]/=gg,fm[j]/=gg;
}
}
Bign FZ(one),FM(one);
for(auto v:fz)FZ=FZ*v;
for(auto v:fm)FM=FM*v;
cout<<FM<<"/"<<FZ<<endl;
//printf("%lld/%lld\n",fm,fz);
}
int main(){init();
int T;
cin>>T;
while(T--)AC();
return ;
}
icpc2018-焦作-E Resistors in Parallel-数论+大数的更多相关文章
- 2018 ACM-ICPC 焦作区域赛 E Resistors in Parallel
Resistors in Parallel Gym - 102028E 吐槽一下,网上搜索的题解一上来都是找规律,对于我这种对数论不敏感的人来说,看这种题解太难受了,找规律不失为一种好做法,但是题解仅 ...
- Resistors in Parallel(找规律+大数)
题意:https://codeforces.com/group/ikIh7rsWAl/contest/254825/problem/E 给你一个n,计算n / Sigma(1~n)的d(是n的只出现一 ...
- HDU 5666 Segment 数论+大数
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- ACM学习历程—HDU5585 Numbers(数论 || 大数)(BestCoder Round #64 (div.2) 1001)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 题目大意就是求大数是否能被2,3,5整除. 我直接上了Java大数,不过可以对末尾来判断2和5, ...
- icpc2018焦作-I. Distance
第一发又超时了... 题目大意:给你n个点,然后给你n-1的数,表示两两距离,然后让你输出n个答案,第i个答案表示从这n个点里面挑i个点,然后这i个点两两之间会有一个距离,答案要求这些距离和的最大值. ...
- ICPC 2018 焦作区域赛
// 2019.10.7 练习赛 // 赛题来源:2018 ICPC 焦作区域赛 // CF链接:http://codeforces.com/gym/102028 A Xu Xiake in Hena ...
- Codeforces - Gym102028 - 2018 Jiaozuo Regional Contest
http://codeforces.com/gym/102028 A. Xu Xiake in Henan Province 看起来像水题.乱搞一下,还真是. #include<bits/std ...
- CodeForces Round 200 Div2
这次比赛出的题真是前所未有的水!只用了一小时零十分钟就过了前4道题,不过E题还是没有在比赛时做出来,今天上午我又把E题做了一遍,发现其实也很水.昨天晚上人品爆发,居然排到Rank 55,运气好的话没准 ...
- codeforces343A A. Rational Resistance
http://http://codeforces.com/problemset/problem/343/A A. Rational Resistance time limit per test 1 s ...
随机推荐
- Jenkins+Jmeter持续集成笔记(一:环境准备)
整体思路: 通过Jmeter图形界面编写api测试脚本 ant 批量执行Jmeter脚本文件 将其集成到jenkins,设置执行频率与发送测试报告 运行环境 系统 配置 IP Centos7.1 1核 ...
- java之xml解析-dom4j
解析方式 XML 解析方式有很多种,但是常用的有两种,如下: DOM Document Object Model:把整个 XML 读到内存中,形成树状结构.整个文档为 Document 对象,属性为 ...
- python基础之 编码进阶,文件操作和深浅copy
1.编码的进阶 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码.即先将其他编码的字符串解码(decode)成unicode,再从unic ...
- random函数的使用
random作为随机函数用处很多,在Python里面也经常使用,特别是处理一些随机事件的时候,特别好用! 废话不多说,直接看下面的例子: random.randomrandom.random() ...
- Gitlab构建分布式版本控制系统
一 安装依赖 1.sudo yum install curl policycoreutils openssh-server openssh-clients 2.sudo systemctl enabl ...
- Javascript根据id获取数组对象
在业务中,列表页跳转详情页时,经常会将Id值传入,然后再根据id值异步获取数据. 假设有服务端的json数据: <注意,这里的data是指已经从后端获取的json, 而非后端原始的文件> ...
- Oracle时间日期函数
ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 ...
- elasticsearch 安装 windows linux macOS
导读 在上一章节我们介绍Elasticsearch基本概念,今天我们继续进行本章内容,Elasticsearch在各种环境下安装,下面将逐一讲解在各种操作系统或不同安装在不同环境中注意事项. 安装 E ...
- 网页分享到微博、QQ、QQ空间、微信
<ul id="content-share-list" class="bdsharebuttonbox bdshare-button-style0-16" ...
- windows安装composer总结
1.直接去网吧下载windows安装EXE程序,傻瓜式安装,so easy. 2.通过命令行安装,可以直接在php目录跑起来 php -r "readfile('https://getcom ...