比赛 |
ZLXOI2015Day1 |
评测结果 |
PPPPPPPPAPWAAWWWWAWW |
题目名称 |
殉国 |
最终得分 |
43 |
用户昵称 |
zhzxcool |
运行时间 |
0.011 s |
代码语言 |
C++ |
内存使用 |
0.29 MiB |
提交时间 |
2015-10-29 09:44:33 |
显示代码纯文本
#include <cstdio>
#include <algorithm>
using namespace std;
int gcd(int x,int y)
{
if (y == 0) return x;
return gcd(y,x % y);
}
int main()
{
freopen("BlackHawk.in","r",stdin);
freopen("BlackHawk.out","w",stdout);
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int ggg = gcd(a,b);
if (a > b) swap(a,b);
int lcma = a/ggg;
int lcmb = b/ggg;
int minans=0,maxans=0;
int r1=-1,r2=-1;
for (int i = 0;i < lcmb;i++)
{
int tmp = a*i;
if (c-tmp<0) break;
if ((c-tmp)%b == 0)
{
r1 = (c-tmp)/b;
minans = i+(c-tmp)/b;
break;
}
}
for (int i = 0;i < lcma;i++)
{
int tmp = b*i;
if (c-tmp<0)break;
if ((c-tmp)%a == 0)
{
r2 = i;
maxans = i+(c-tmp)/a;
break;
}
}
if (r1<0) puts("-1 -1"),puts("0");
else
{
printf("%d %d\n",r1,r2);
printf("%d",(r1-r2)/(lcma)+1);
}
fclose(stdin);
fclose(stdout);
return 0;
}