ACM:Leo's Trial(1)

Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, …) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?

Input
The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.
Output
Print a single integer — the answer to the problem.
Examples
Input
2 2
Output
3
Input
9 3
Output
13
Note
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.

AC:

#include<stdio.h>
int main()
{
	int n = 0,m = 0,k = 0,a,i = 0,day = 0;
	scanf("%d %d",&n,&m);

	if (n<m)
		day = n;
	else if (n==m)
		day = n + 1;
	else
	{
		for (i=1;i<=n+k;i++)
		{
			if (i%m==0)
				k += 1;	
		}
		day = i - 1;
	}
	printf("%d\n",day);

	return 0;
}

Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.
Input

The only line of input contains integers n and k (1 ≤ k ≤ n ≤ 1012).

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

Print the number that will stand at the position number k after Volodya's manipulations.

Examples
Input
10 3
Output
5
Input
7 7
Output
6
Note
In the first sample Volodya’s sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.

AC:

#include <stdio.h>
#include <stdlib.h>
int main()
{
	long long a = 0,b = 0,result = 0;
	scanf("%lld%lld",&a,&b);

	if(a%2)
		a=a/2+1;
	else
		a=a/2;
	if(b<=a)
		result=b*2-1;
	else
		result=(b-a)*2;
	printf("%lld\n",result);

	return 0;    
}

Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.

Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.

Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input
The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).
Output
Print a single integer — the number of hours Vasily can light up the room for.
Examples
Input
4 2
Output
7
Input
6 3
Output
8
Note
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

AC:

#include <stdio.h>
#include <string.h>

int main()
{
	int sum = 0, a, b;
	scanf("%d%d", &a, &b);
	while (a >= b) 
	{
		sum += (a / b) * b;
		a = a / b + a % b;
	}
	printf("%d\n", sum + a);
	return 0;
}

要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
Input
数据的第一行是一个T,表示有T组数据。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
Output
对应每组数据输出(A/B)%9973。
Sample Input
2
1000 53
87 123456789
Sample Output
7922
6060

AC:

#include<stdio.h>
int main()
{
	int i,a1 = 0,a2 = 0,total= 0;
	scanf("%d",&total);
	
	while(total--)
	{
		scanf("%d%d",&a1,&a2);
		for(i=0;i<9973;i++)
			if((((a2%9973)*i)%9973-a1)%9973==0)
				break;
			printf("%d\n",i);      
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值