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 ...
随机推荐
- 18.1-uC/OS-III等待多个内核对象
等待的多个内核对象是指多值信号量和消息队列的任意组合 . 如果想要使用“等待多个内核对象”,就必须事先使能“等待多个内核对象”.“等待多个内核对象” 的使能位于“os_cfg.h”. 1.OSPend ...
- Java连接MySQL报出警告 WARN: Establishing SSL connection without server's identity verification is not recommended.
很多人使用JDBC连接MySQL时报出警告: WARN: Establishing SSL connection without server's identity verification is n ...
- 【English】【托业】【四六级】写译高频词汇
大家都知道,四六级翻译每次考的话题不可能原句直接重复,但是,在研究了近几年的四六级真题后,我们惊奇地发现: 写译词汇在重复考! 写译词汇在重复考! 写译词汇在重复考! 因此,小编为大家整理了四六级写译 ...
- 【LeetCode每天一题】Spiral Matrix II(螺旋数组II)
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral ord ...
- Python WebSocket长连接心跳与短连接
python websocket 安装 pip install websocket-client 先来看一下,长连接调用方式: ws = websocket.WebSocketApp("ws ...
- laravel----------laravel5.3调度任务以及Artisan
1.在使用的过程中会遇到有些函数不能用需要在php配置文件里面打开: disable_functions = exec,passthru,popen,proc_open,shell_exec,syst ...
- XML DOM 节点类型(Node Types)
节点类型 下面的表格列出了不同的 W3C 节点类型,以及它们可拥有的子元素: 节点类型 描述 子元素 Document 表示整个文档(DOM 树的根节点) Element (max. one) Pro ...
- Tomcat增加Context配置不带项目名访问导致启动的时候项目加载两次
eclipse发布web应用至tomcat,默认方式下访问该项目是需要带项目名称的,例http://localhost:8080/myapp/.现在需要改成这样访问http://localhost.修 ...
- 转:图解C#的值类型,引用类型,栈,堆,ref,out
C# 的类型系统可分为两种类型,一是值类型,一是引用类型,这个每个C#程序员都了解.还有托管堆,栈,ref,out等等概念也是每个C#程序员都会接触到的概念,也是C#程序员面试经常考到的知识,随便搜搜 ...
- 快速搭建Vue项目
快速搭建Vue项目 第一次安装vue项目Vue推荐开发环境Node.js 6.2.0.npm 3.8.9.webpack 1.13.vue-cli 2.5.1.webstrom2016 安装环境: 安 ...