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 ...
随机推荐
- 解决端口耗尽问题: tcp_tw_reuse、tcp_timestamps
一.本地端口有哪些可用 首先,需要了解到TCP协议中确定一条TCP连接有4要素:local IP, local PORT, remote IP, remote PORT.这个四元组应该是唯一的. 在我 ...
- k-means性能测试
clf = MiniBatchKMeans(n_clusters=5000, batch_size=5000, n_init=1, max_iter=200, max_no_improvement=1 ...
- 原生js阻止表单跳转
/* W3C浏览器下的 */ var forms = document.getElementById("from") forms.addEventListener('submit' ...
- Sitecore开发 IP地理定位服务入门
如果您是营销人员或开发人员,并且有兴趣在Sitecore安装中使用Sitecore IP Geolocation服务,那么本文就是为您准备的. 借助Sitecore IP地理定位服务,您网站的访问者可 ...
- EasyUI表格DataGrid格式化formatter用法
1.通过HTML标签创建数据表格时使用formatter <!DOCTYPE html> <html> <head> <meta charset=" ...
- 【2】Kali之情报搜集技术
渗透测试中情报搜集需要完成两项重要任务: 1.通过信息搜集工作,确定渗透测试目标范围. 2.通过情报信息搜集,发现渗透测试目标的安全漏洞与脆弱点,为后续的渗透攻击提供基础. 通过DNS和IP地址挖掘目 ...
- qt creator中编辑Makefile的设置
在qt creator中编辑Makefile时的Tab键总是不能识别,需要这样设置
- 基于CSS属性display:table的表格布局的使用
项目改造中遇到DIV+CSS实现的table,新需求需要在表格使用单元格合并,网上调查返现CSS display:table实现的table表格,没有单元格的属性和样式,经过一番思考,曲折现实了单元格 ...
- Linux实现VLAN
交换机的端口有两种配置模式:Access和Trunk. Access口:端口属于VLAN,VLAN ID 1~4096.直接与计算机网卡相连,流入该口的数据包都被打上VLAN的标签. Trunk口:允 ...
- P1636 Einstein学画画
一笔画问题 P1636 Einstein学画画 如果一个图存在一笔画,则一笔画的路径叫做欧拉路,如果最后又回到起点,那这个路径叫做欧拉回路. 奇点:跟这个点相邻的边数目有奇数个的点 不存在奇数个奇点的 ...