QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#17315. Sqrt Problem

Statistics

Sqrt Problem

  • 时间限制:$1.0$ 秒
  • 空间限制:$512\text{ Mib}$

题目描述

给定一个整数 $n$,你可以对其进行下面的两种操作:

  • $n \leftarrow n+2$,即将 $n$ 增加 $2$。
  • 若 $\sqrt n$ 为整数,则 $n \leftarrow \sqrt n$,即将 $n$ 开方。进行此操作后你获得 $1$ 分。

你需要求出获得 $k$ 分所至少需要进行的操作数量。

输入格式

本题包含多组测试数据。

输入的第一行包含两个非负整数 $c,t$,分别表示测试点编号与测试数据组数。$c=0$ 表示该测试点为样例。

接下来依次输入每组测试数据,对于每组测试数据:

  • 共一行,包含两个正整数 $n,k$。

输出格式

对于每组测试数据:

  • 输出一行,包含一个整数,表示获得 $k$ 分所至少需要进行的操作数量。

样例 1 输入

0 5
6 1
1 3
14514 23333
2011112920110906 1
3 1919810233114514

样例 1 输出

6
3
46860
15268726
7679240932458056

样例 1 解释

本组样例包含 $5$ 组测试数据。

  • 对于第 $1$ 组测试数据,依次进行 $5$ 次第 $1$ 种操作和 $1$ 次第 $2$ 种操作即可。可以证明至少需要进行 $6$ 次操作。
  • 对于第 $2$ 组测试数据,进行 $3$ 次第 $2$ 种操作即可。可以证明至少需要进行 $3$ 次操作。

数据范围

对于所有测试数据,均有:

  • $1 \le t \le 10^5$;
  • $1 \le n,k \le 10^{18}$。
测试点编号 $n \le$ $k\le$ 特殊性质
$1$ $1$ $10^5$
$2$ $1$ $10^{18}$
$3$ $2$ $10^{5}$
$4$ $2$ $10^{18}$
$5$ $10^5$ $1$
$6$ $10^{18}$ $1$
$7$ $10^5$ $10^5$
$8$ $10^9$ $10^9$
$9$ $10^9$ $10^9$
$10$ $10^{18}$ $10^{18}$
  • 特殊性质:保证 $t=3$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.