A. Jamie and Alarm Snooze

Codeforces
IDCF916A
Time2000ms
Memory256MB
Difficulty
brute forceimplementationmath
English · Original
Chinese · Translation
Formal · Original
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly _hh_: _mm_. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a _lucky_ time. He will then press the snooze button every _x_ minutes until _hh_: _mm_ is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered _lucky_ if it contains a digit '7'. For example, 13: 07 and 17: 27 are _lucky_, while 00: 48 and 21: 34 are not _lucky_. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a _lucky_ time Jamie can set so that he can wake at _hh_: _mm_. Formally, find the smallest possible non-negative integer _y_ such that the time representation of the time _x_·_y_ minutes before _hh_: _mm_ contains the digit '7'. Jamie uses 24-hours clock, so after 23: 59 comes 00: 00. ## Input The first line contains a single integer _x_ (1 ≤ _x_ ≤ 60). The second line contains two two-digit integers, _hh_ and _mm_ (00 ≤ _hh_ ≤ 23, 00 ≤ _mm_ ≤ 59). ## Output Print the minimum number of times he needs to press the button. [samples] ## Note In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is _lucky_.
Jamie 喜欢睡觉。一天,他决定必须在恰好 #cf_span[hh: mm] 醒来。然而,他讨厌醒来,因此他希望通过将闹钟设在一个 _幸运_ 的时间来减轻醒来时的痛苦。他将在每个 #cf_span[x] 分钟后按下一次睡眠按钮,直到时间到达 #cf_span[hh: mm] 时才真正醒来。他想知道他最少需要按多少次睡眠按钮。 一个时间被认为是 _幸运_ 的,如果它包含数字 '#cf_span[7]'。例如,#cf_span[13: 07] 和 #cf_span[17: 27] 是 _幸运_ 的,而 #cf_span[00: 48] 和 #cf_span[21: 34] 则不是 _幸运_ 的。 注意,闹钟设置的时间和醒来时间不一定在同一天。题目保证存在一个 _幸运_ 时间,使得 Jamie 能够在 #cf_span[hh: mm] 醒来。 形式化地,求最小的非负整数 #cf_span[y],使得在 #cf_span[hh: mm] 前 #cf_span[x·y] 分钟的时间表示中包含数字 '#cf_span[7]'。 Jamie 使用 24 小时制,因此 #cf_span[23: 59] 之后是 #cf_span[00: 00]。 第一行包含一个整数 #cf_span[x] (#cf_span[1 ≤ x ≤ 60])。 第二行包含两个两位数的整数 #cf_span[hh] 和 #cf_span[mm] (#cf_span[00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59])。 请输出他最少需要按按钮的次数。 在第一个样例中,Jamie 需要在 11:23 醒来。因此,他可以将闹钟设在 11:17。当闹钟在 11:17 和 11:20 响起时,他会按下睡眠按钮。 在第二个样例中,Jamie 可以直接将闹钟设在 01:07,这是一个 _幸运_ 时间。 ## Input 第一行包含一个整数 #cf_span[x] (#cf_span[1 ≤ x ≤ 60])。第二行包含两个两位数的整数 #cf_span[hh] 和 #cf_span[mm] (#cf_span[00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59])。 ## Output 请输出他最少需要按按钮的次数。 [samples] ## Note 在第一个样例中,Jamie 需要在 11:23 醒来。因此,他可以将闹钟设在 11:17。当闹钟在 11:17 和 11:20 响起时,他会按下睡眠按钮。在第二个样例中,Jamie 可以直接将闹钟设在 01:07,这是一个 _幸运_ 时间。
Let $ x \in \mathbb{Z}^+ $, $ 1 \leq x \leq 60 $, be the snooze interval in minutes. Let $ T = (h, m) $, where $ 0 \leq h \leq 23 $, $ 0 \leq m \leq 59 $, be the wake-up time in 24-hour format. Define the time $ t_y $ as the time $ y \cdot x $ minutes before $ T $, for non-negative integers $ y $. Let $ t_y $ be represented in 24-hour format as a 4-digit string $ HHMM $, where leading zeros are included. A time is *lucky* if its string representation contains the digit '7'. Find the smallest non-negative integer $ y $ such that the string representation of $ t_y $ contains the digit '7'. Note: Time wraps around modulo 1440 (number of minutes in a day).
Samples
Input #1
3
11 23
Output #1
2
Input #2
5
01 07
Output #2
0
API Response (JSON)
{
  "problem": {
    "name": "A. Jamie and Alarm Snooze",
    "description": {
      "content": "Jamie loves sleeping. One day, he decides that he needs to wake up at exactly _hh_: _mm_. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a _lucky_ time",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF916A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Jamie loves sleeping. One day, he decides that he needs to wake up at exactly _hh_: _mm_. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a _lucky_ time...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Jamie 喜欢睡觉。一天,他决定必须在恰好 #cf_span[hh: mm] 醒来。然而,他讨厌醒来,因此他希望通过将闹钟设在一个 _幸运_ 的时间来减轻醒来时的痛苦。他将在每个 #cf_span[x] 分钟后按下一次睡眠按钮,直到时间到达 #cf_span[hh: mm] 时才真正醒来。他想知道他最少需要按多少次睡眠按钮。\n\n一个时间被认为是 _幸运_ 的,如果它包含数字 '#cf_span[...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ x \\in \\mathbb{Z}^+ $, $ 1 \\leq x \\leq 60 $, be the snooze interval in minutes.  \nLet $ T = (h, m) $, where $ 0 \\leq h \\leq 23 $, $ 0 \\leq m \\leq 59 $, be the wake-up time in 24-hour format.\n\nDef...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments