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. Apache+php搭建

    首先安装Apache -->下载 修改httpd.conf文件 # # This is the main Apache HTTP server configuration file. It co ...

  2. TensorFlow使用记录 (九): 模型保存与恢复

    模型文件 tensorflow 训练保存的模型注意包含两个部分:网络结构和参数值. .meta .meta 文件以 “protocol buffer”格式保存了整个模型的结构图,模型上定义的操作等信息 ...

  3. P1598 垂直柱状图

    输入格式: 四行字符,由大写字母组成,每行不超过100个字符 输出格式: 由若干行组成,前几行由空格和星号组成,最后一行则是由空格和字母组成的.在任何一行末尾不要打印不需要的多余空格.不要打印任何空行 ...

  4. 「CSA Round #41」BFS-DFS

    题目链接 戳我 \(Description\) 给出一个图的\(bfs\)序和\(dfs\)序,构造出一个满足条件的图,边的扫描顺序为读入顺序 \(Solution\) 这个题还是很简单的. 先来看看 ...

  5. 安装ubuntu是所需的引导

    title Install Ubuntu root (hd0,0) kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/ubuntu-16.04 ...

  6. 【实用软件】GIF屏幕录制软件-ScreenToGif (在GitHub开源)

    抛个问题,自问自答 ScreenToGif 经常会遇到一些场景,需要你向别人展示一些操作或是效果——例如告诉别人某某软件的配置步骤啊.刚某个动画效果怎么样啊.某某电影里面的一个镜头多么经典啊.打得大快 ...

  7. LC 687. Longest Univalue Path

    Given a binary tree, find the length of the longest path where each node in the path has the same va ...

  8. vue文件流转换成pdf预览(pdf.js+iframe)

    参考文档:https://www.jianshu.com/p/242525315bf6 PDFJS: https://mozilla.github.io/pdf.js/     支持获取文件流到客户端 ...

  9. APT软件包管理-在线安装

    APT (Advanced Packaging Tool高级软件包工具) 是一个强大的包管理系统,而那些图形化程序如 添加/删除 应用程序 都是建立 在它的基础之上的.有了dpkg后,Debian再次 ...

  10. shell 部分语法

    语法: variable_name=${variable_name:-xxxx} 如果variable 已经有值,则不被新值覆盖,否则将新值赋给variable split命令切割文件