13.kuangbin 簡單搜索 - HDU - 1495 非常可樂 (數論是最簡單的)

(這道題用數論做最簡單了,bfs稍后補上!!!)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
//#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
int w = 1, s = 0;
char ch = getchar();
while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); }
return s * w;
//最大公約數
}
int gcd(int x,int y) {
if(x<y) swap(x,y);//很多人會遺忘,大數在前小數在后
return x % y ? gcd(y, x % y) : y;
}
int lcm(int x,int y)//計算x和y的最小公倍數
{
return x*y/gcd(x,y);//使用公式
}
//------------------------ 以上是我常用模板與刷題幾乎無關 ------------------------//
int main()
{
int a, b, c;
while (scanf("%d%d%d", &a,&b,&c), a+b+c) {
a /= gcd(b,c);
if (a & 1)
printf("NO\n");
else
printf("%d\n", a - 1);
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/142298.html
標籤:其他
