UVA10880 Colin and Ryan整除
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10880 Colin and Ryan整除相关的知识,希望对你有一定的参考价值。
“As a special bonus, if they order
by midnight, what would they receive?
Colin: They’d receive it earlier than if
they’d ordered it later.
Songs of the Butcher
Colin and Ryan had a party. They baked C cookies and invited G guests. Each guest ate Q cookies, and R cookies were left (R < Q).
Input
The first line of input gives the number of cases, N. N test cases follow. Each one is a line containing C and R (at most 2000000000).
Output
For each test case, output one line containing ‘Case #x:’ followed by Q — the number of cookies each guest ate. If there are multiple answers, print them in increasing order, separated by spaces. Do not print trailing spaces. Print a ‘0’ in the case when R = C.
Sample Input
4
10 0
13 2
300 98
1000 997
Sample Output
Case #1: 1 2 5 10
Case #2: 11
Case #3: 101 202
Case #4:
问题链接:UVA10880 Colin and Ryan
问题简述:总共C块饼干,请G个客人吃,每人吃Q块,余下R块。给定C和R,问每位客人可以吃多少块饼干,有多种解,从小到大输出这些解。
问题分析:整除问题,求C-R的因子即可,用STL的set来排序。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10880 Colin and Ryan */
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t, caseno = 0;
scanf("%d", &t);
while (t--) {
int c, r;
scanf("%d%d", &c, &r);
int diff = c - r;
printf("Case #%d:", ++caseno);
if (diff == 0)
printf(" 0\\n");
else {
set<int> ans;
for (int i = 1; i * i <= diff; i++)
if (diff % i == 0) {
ans.insert(diff / i);
ans.insert(i);
}
for (set<int>::iterator iter = ans.begin(); iter != ans.end(); iter++)
if (*iter > r) printf(" %d", *iter);
printf("\\n");
}
}
return 0;
}
以上是关于UVA10880 Colin and Ryan整除的主要内容,如果未能解决你的问题,请参考以下文章