C - Candies

Polycarpus has got n candies and m friends (n ≥ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.

For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.

Input

The single line of the input contains a pair of space-separated positive integers n,m (1 ≤ n, m ≤ 100;n ≥ m) — the number of candies and the number of Polycarpus's friends.

Output

Print the required sequence a1, a2, ..., am, where ai is the number of candies in thei-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.

Examples
Input
12 3
Output
4 4 4 
Input
15 4
Output
3 4 4 4 
Input
18 7
Output
2 2 2 3 3 3 3 
#include<stdio.h>
int main(void)
{
    int n,m,a,b,i,ar[1000];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
         a=n%m;
         b=n/m;
        for(i=1;i<=m;i++) ar[i]=b;
        for(i=m-a+1;i<=m;i++)  ar[i]+=1;
        for(i=1;i<m;i++) printf("%d ",ar[i]);
        printf("%d\n",ar[i]);
    }


}
阅读更多

Who Gets the Most Candies?

10-31

DescriptionnnN children are sitting in a circle to play a game.nnThe children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from theK-th child, who tells all the others the integer on his card and jumps out of the circle. The integer on his card tells the next child to jump out. LetA denote the integer. If A is positive, the next child will be theA-th child to the left. If A is negative, the next child will be the (−A)-th child to the right.nnThe game lasts until all children have jumped out of the circle. During the game, thep-th child jumping out will get F(p) candies where F(p) is the number of positive integers that perfectly divide p. Who gets the most candies?nnInputnnThere are several test cases in the input. Each test case starts with two integersN (0 < N ≤ 500,000) and K (1 ≤ K ≤ N) on the first line. The next N lines contains the names of the children (consisting of at most 10 letters) and the integers (non-zero with magnitudes within 108) on their cards in increasing order of the children’s numbers, a name and an integer separated by a single space in a line with no leading or trailing spaces.nOutputnnOutput one line for each test case containing the name of the luckiest child and the number of candies he/she gets. If ties occur, always choose the child who jumps out of the circle first.nnSample Inputnn4 2nTom 2nJack 4nMary -1nSam 1nSample OutputnnSam 3

没有更多推荐了,返回首页