The following code is my submission for Codeforces 1244C The Football Season.

import io
import sys
import math def inverse(a, m):
u = 0
v = 1
while a != 0:
t = m // a
m -= t * a
a, m = m, a
u -= t * v
u, v = v, u
assert m == 1
return u def main():
# It helps to use a input file when testing or debugging your code locally.
# with open("main.in", "r", encoding='utf-8') as f:
with sys.stdin as f:
n, p, w, d = map(int, f.readline().split())
g = math.gcd(w, d)
if p % g:
print(-1)
return
W = w // g
D = d // g
x = inverse(W, D)
y = (1 - W * x) // D
assert W * x + D * y == 1
m = p // g
x *= m
y *= m
ub = min(x // D, (n - x - y) // (W - D))
lb = (-y + W - 1) // W
if lb > ub:
print(-1)
return
X = x - lb * D
Y = y + lb * W
assert X >= 0 and Y >= 0 and X * w + Y * d == p and X + Y <= n
print(X, Y, n - X - Y)
main()

Notes:

  1. // does floor divison in Python.

References

Python 中的 int 可以表示任意大小的整数

Python input/output boilerplate for competitive programming的更多相关文章

  1. Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.

    from:https://www.v2ex.com/amp/t/463719 系统环境是 Windows 10 Pro,Docker 版本 18.03.1-ce,电脑开机之后第一次运行 docker ...

  2. PHP-FPM-failed to ptrace(PEEKDATA) pid 123: Input/output error

    If you're running PHP-FPM you can see these kind of errors in your PHP-FPM logs. $ tail -f php-fpm.l ...

  3. NFS挂载异常 mount.nfs: Input/output error

    [root@localhost ~]# vi /etc/exports #增加/nfs 192.168.10.132(rw,no_root_squash,no_all_squash,async) [r ...

  4. BIOS(Basic Input/Output System)是基本输入输出系统的简称

    BIOS(Basic Input/Output System)是基本输入输出系统的简称 介绍 操作系统老师说,平时面试学生或者毕业答辩的时候他都会问这个问题,可见这个问题对于计算机专业的学生来说是如此 ...

  5. read()、write()返回 Input/output error, Device or resource busy解决

    遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...

  6. Angular 个人深究(三)【由Input&Output引起的】

    Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...

  7. dpdk EAL: Error reading from file descriptor 23: Input/output error

    执行test程序时输出: EAL: Error reading from file descriptor 23: Input/output error 原因: 在虚拟机添加的网卡,dpdk不支持导致的 ...

  8. python's output redirect

    [python's output redirect] fin = open("xx.txt", 'r'); print >>fin, "hello world ...

  9. html5 填表 表单 input output 与表单验证

    1.<output>     Js计算结果 <form oninput="res.value = num1.valueAsNumber*num2.valueAsNumber ...

随机推荐

  1. 圆桌游戏(区间DP)

    2.圆桌游戏 (game.cpp/c/pas) [问题描述] 有一种圆桌游戏是这样进行的:n个人围着圆桌坐成一圈,按顺时针顺序依次标号为1号至n号.对1<=i<=n的i来说,i号的左边是i ...

  2. BAT 鼎立格局被打破,2019 年这些互联网公司是程序员跳槽首选!

    点击上方“程序员江湖”,选择“置顶或者星标” 你关注的就是我关心的! ​ 作者:BOSS直聘 来源:BOSS直聘 作者:BOSS直聘(ID:bosszhipin),领先的移动互联网招聘APP,为求职者 ...

  3. 【译】OkHttp3 拦截器(Interceptor)

    一,OkHttp 拦截器介绍(译自官方文档) 官方文档:https://github.com/square/okhttp/wiki/Interceptors 拦截器是 OkHttp 提供的对 Http ...

  4. java 百度地图判断两点距离2

    package baiduApi; public class BaiDuMap { static double DEF_PI = 3.14159265359; // PI static double ...

  5. [转]html中meta作用

    meta是html语言head区的一个辅助性标签.几乎所有的网页里,我们可以看到类似下面这段的html代码:  <head>  <meta http-equiv="cont ...

  6. SUSE系列---修改IP和hosts文件

    有些时候我们需要修改linux系统的IP,此时我们要注意,修改IP之后,如果我们如果不修改hosts文件,那么可能我们一些服务会无法使用:下面分别记录修改IP和hosts文件的方法: 修改IP: 打开 ...

  7. 简易的美图秀秀利用别人的so库

    在实际开发中,有时候时间短,任务量大,可以查看类似的apk,将行apk反编译,通过看源码分析,用里面的JNI代码! 本案例中用了美图秀秀的JNI.java和jni.so链接库 项目中调用别人写的c代码 ...

  8. SQL学习(八)日期处理

    不同数据库中,针对日期处理的函数不同 Oracle中常用日期函数 (1.sysdate: 获取当前系统时间 如: select sysdate() ----返回当前时间,包括年月日 时分秒 (2.to ...

  9. openstack部署keystone

    环境: 免密钥,域名解析 cat /etc/hosts 192.168.42.120 controller 192.168.42.121 compute 192.168.42.122 storage ...

  10. java源码-CountDownLatch源码分析

    这次分析CountDownLatch,相信大部分人都用过把! CountDownLatch内部还是Sync对象,还是基础AQS(可见其重要性),首先看一下CountDownLatch初始化,Count ...