30-days-challnenge-newton-s-

30 days challenge

day 6

Bob and Hammer Time Limit: 2 sec Memory Limit: 128000 kB Problem Statement Bob is at the origin of a number line. He wants to reach a goal at coordinate X. There is a wall at coordinate Y, which Bob cannot go beyond at first. However, after picking up a hammer at coordinate Z, he can destroy that wall and pass through. Determine whether Bob can reach the goal. If he can, find the minimum total distance he needs to travel to do so. Input The input is given from Standard Input in the following format:

X Y Z

Constraints −1000≤X, Y, Z≤1000 X, Y, and Z are distinct, and none of them is 0. All values in the input are integers. Output If Bob can reach the goal, print the minimum total distance he needs to travel to do so. If he cannot, print -1 instead. Example Sample Input 1 10 -10 1 Sample Output 1 10

Sample Input 2 20 10 -10 Sample Output 2 40

#day10 Bacterias Time Limit: 2 sec Memory Limit: 128000 kB Problem Statement There are A Bacterias. Each time Jerry shouts, the bacterias multiply by K times. In order to have B or more slimes, at least how many times does Jerry need to shout? Input Input is given from Standard Input in the following format: A B K

Constraints 1≤A≤B≤10^9 2≤K≤10^9 All values in input are integers. Output Print the answer. Example Sample Input 1 1 4 2 Sample Output 1 2

Sample Input 2 7 7 10 Sample Output 2 0

Sample Input 3 31 415926 5 Sample Output 3 6

#Day 11 Unlucky Seven Time Limit: 2 sec Memory Limit: 128000 kB Problem Statement Mahi hates the number 7.

We are interested in integers without the digit 7 in both decimal and octal. How many such integers are there between 1 and N (inclusive)? Input Input is given from Standard Input in the following format: N

Constraints 1≤N≤10^5

N is an integer. Output Print an integer representing the answer. Example Sample Input 1 20 Sample Output 1 17 Sample Input 2 100000 Sample Output 2 30555