CodeForces - 415B Mashmokh and Tokens

Bimokh is Mashmokh‘s boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can‘t use it in any other day to get more money. If a worker gives back w tokens then he‘ll get dollars.

Mashmokh likes the tokens however he likes money more. That‘s why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1,?x2,?...,?xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

Input

The first line of input contains three space-separated integers n,?a,?b (1?≤?n?≤?105; 1?≤?a,?b?≤?109). The second line of input contains n space-separated integers x1,?x2,?...,?xn (1?≤?xi?≤?109).

Output

Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

Example

Input

5 1 412 6 11 9 1

Output

0 2 3 1 1 

Input

3 1 21 2 3

Output

1 0 1 

Input

1 1 11

Output

0 


 1 #include<iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 long long int num[100010];
 5 int main()
 6 {
 7     int n;
 8     while(cin>>n)
 9     {
10         long long int a,b;
11         scanf("%lld%lld",&a,&b);
12         for(int i=0;i<n;i++)
13             cin>>num[i];
14         long long int ans;
15         for(int i=0;i<n;i++)
16         {
17             ans=((num[i]*a)%b)/a;
18             printf("%lld ",ans);
19         }
20         cout<<endl;
21     }
22     return 0;
23 }


				
时间: 2024-10-22 00:39:08

CodeForces - 415B Mashmokh and Tokens的相关文章

Round #240 B. Mashmokh and Tokens(Div.2)

Bimokh is Mashmokh's boss. For the following ndays he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens ba

Codeforces 414B Mashmokh and ACM(DP)

Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tas

CodeForces 415D Mashmokh and ACM

$dp$. 记$dp[i][j]$表示已经放了$i$个数字,并且第$i$个数字放了$j$的方案数.那么$dp[i][j] = \sum\limits_{k|j}^{}  {dp[i - 1][k]}$ #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorit

CodeForces 414B - Mashmokh and ACM

给你长度为 l 的整数数列b1, b2, ..., bl(1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n) 如果这个数列被称为好的,那么每个元素都可以整除下一个元素 给你n和k,去找到长度为k的好数列的个数 dp[任意i][1] = 1: dp[i的倍数][长度k] = dp[i][长度k-1] + 1; 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 const int MOD = 100

codeforces D.Mashmokh and ACM

题意:给你n和k,然后找出b1, b2, ..., bl(1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n),并且对所有的bi+1%bi==0,问有多少这样的序列? 思路:dp[i][j] 表示长度为i,以j为结尾有多少.dp[i][j]+=dp[i-1][s],j%s==0; 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 const

codeforces C. Mashmokh and Numbers

题意:给你n和k,然后让你找出n个数使得gcd(a1,a2)+gcd(a3,a4)+......的和等于k: 思路:如果n为奇数,让前n-3个数的相邻两个数都为1,n-2和n-1两个数gcd为k-ans:ans为前n-3个数的和.为偶数的话,让前n-2个数的相邻两个数都为1,n和n-1两个数gcd为k-ans: 1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <vecto

Codeforces Round #240 (Div. 2) (ABCDE题解)

题目链接:http://codeforces.com/contest/415 A. Mashmokh and Lights time limit per test:1 second memory limit per test:256 megabytes Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are index

dp题目列表

10271 - Chopsticks 10739 - String to Palindrome 10453 - Make Palindrome 10401 - Injured Queen Problem 825 - Walking on the Safe Side 10617 - Again Palindrome 10201 - Adventures in Moving - Part IV 11258 - String Partition 10564 - Paths through the Ho

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734