非常可乐

题目

样例

这题本来用的bfs写了150多行,太长了,结果查了一下数论的做法,结果只要20行就做好了,会数学的果然都是大佬啊!

话不多说直接上数论的代码,再转载一下解释

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int main()
{
	int s, n, m;
	while (cin >> s >> n >> m, s + m + n){
		s /= gcd(n, m);
		if (s & 1)
			cout << "NO" << endl;
		else
			cout << s - 1 << endl;
	}
	return 0;
}

下面是转载的解释:

https://blog.csdn.net/V5ZSQ/article/details/52097459

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值