Rational Resistance CodeForces - 343A

原题链接
考察:数论
思路:
  串联: \(\frac{a}{b}+1 = \frac{a+b}{b}\)
  并联: \(\frac{a}{b}与1并联--> \frac{a}{a+b}\)
  也就是说分子分母不论大小可以得到相同的结果

Code

#include <iostream> 
#include <cstring>
using namespace std;
typedef long long LL;
LL a,b,ans;
int main()
{
	scanf("%lld%lld",&a,&b);
	while(1)
	{
		if(a<b)
		{
			b-=a;
			swap(a,b);
			ans++;
		}
		ans+=a/b;
		a=a%b;
		if(!a||!b) break;
	}
	printf("%lld\n",ans);
	return 0;
}
posted @ 2021-07-24 15:52  acmloser  阅读(30)  评论(0编辑  收藏  举报