Rise of Shadows

题目:https://codeforces.com/gym/103202/problem/I

Azeroth is a world full of fantasy. In Azeroth, there are H hours in a day and M minutes in an hour.

You found a clock made from Azeroth. The clock has two hands — the hour hand and the minute hand. The two hands point to the same direction at the start of a day. Either hand rotates at a constant speed. The hour hand goes around a full circle in H hours and the minute hand goes around a full circle in M minutes. Surprisingly, it is night in Azeroth if and only if the angle between the two hands is less than or equal to α.

Now you’re wondering, given α=2πAHM, how many integral moments (i.e., integer minutes since the start of the day) are there, such that the angle between the two hands is less than or equal to α.

Input
The only line of the input contains three integers H,M (2≤H,M≤109) and A (0≤A≤HM2), representing the number of hours in a day and the number of minutes in an hour, and the limit of the angle in radians, respectively.

Output
Print an integer representing the answer.

Examples
inputCopy
5 5 4
outputCopy
9
inputCopy
3 5 1
outputCopy
3

理解不来,没看过数论的东西就觉得太难了,虽然代码简单,但是还是搞不懂为什么可以这样得出结论

以下证明:

在这里插入图片描述
大佬的证明:
考虑到该方程要等于【0,K】时才有效,考虑到该方程有解的前提是Ki 整除gcd(n-1,m),因此可以快速计算出有效的K有 K/gcd(n-1,m)个,考虑到绝对值的关系,每组还要乘2。 再考虑下K=0,记为1 ,对于K=0 不难发现只有gcd(n-1,m)组解,同理对于其他有效K。那么最终答案为 (K/g*2+1)*g

AC代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

long long gcd(long long a,long long b){
	
	return b ? gcd(b,a%b) : a;
}

int main(){
	
	
	long long H,M,A;
	
	scanf("%lld%lld%lld",&H,&M,&A);
	
	long long ans = 0;
	
	long long G = gcd(H-1,M);
	
	
	printf("%lld",min(H*M,G * (2 * (A / G) + 1)));
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值