### Background

Petty bureaucrat Victor Thiefton was disposed towards stealing from his childhood. But one thing is to legally privatize national factories, diamond fields and oil derricks at the cost of billions dollars. And another thing is to filch some money from a poor regional budget. Our legislation is very strict. Therefore Victor felt that justice is on the alert just after he extracted his hand from the national pocket. What should he do to escape inevitable punishment?
Mr. Thiefton has once heard that in accordance with the criminal legislation standards he would be condemned to long imprisonment for a theft whereas in case of a peculation he could escape with a suspended sentence only. So if the most part of stolen money is peculated, the duration of imprisonment will be reduced.

### Problem

The same evening Mr. Thiefton burst into "MegaApril" superstore and rushed for overflowing storefronts carrying a purse with N stolen dollars. It appeared that unlimited number of high-quality goods and goods at moderate price were on sale in the superstore. High-quality goods cost A dollars per piece, and goods at moderate price cost B dollars per piece. Victor should spend as much stolen money as possible to reduce the duration of imprisonment to a minimum.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
using namespace std;

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

int main()
{
int a,b,n,g,t,res,x,y;
scanf("%d %d %d",&a,&b,&n);
bool flag=false;
if(a<b){
swap(a,b);
flag=true;
}
g=gcd(a,b);
n/=g;
a/=g;
b/=g;
t=n/a;
res=n;
x=y=0;
for(int i=0;i<=t;++i){
if(res>(n-i*a)%b){
x=i;y=(n-i*a)/b;
res=n-x*a-y*b;
if(res==0)break;
}
}
if(flag)
printf("%d %d\n",y,x);
else
printf("%d %d\n",x,y);
return 0;
}

#### Ural 1430. Crime and Punishment(数论)

2014-01-23 23:50:44

#### 1.4 Crime and Punishment

2017-02-12 19:47:22

#### Ural 1430. Crime and Punishment

2013-08-05 16:50:00

#### Is punishment necessary to help children learn the difference between right and wrong?

2017-07-22 17:33:36

#### San Francisco Crime Classification(Kaggle)

2015-09-14 22:55:40

#### Android权威指南 ——crimeIntent

2017-11-29 17:06:16

#### Android编程权威指南（第2版）—第14章挑战练习

2017-09-10 17:11:53

#### 《Android编程权威指南（第三版）》第十三章挑战练习Demo

2018-04-16 20:40:31

#### 常见的HTTPS攻击方法

2014-12-31 14:22:19

#### 美国科学院学报:如何在竞争激烈的环境下维持稳定的群体

2017-12-22 00:00:00

## 不良信息举报

Crime and Punishment