CF1933C.Turtle Fingers: Count the Values of k

普及-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given three positive integers aa, bb and ll (a,b,l>0a,b,l \gt 0).

It can be shown that there always exists a way to choose non-negative (i.e. ≥0\ge 0) integers kk, xx, and yy such that l=k⋅ax⋅byl = k \cdot a^x \cdot b^y.

Your task is to find the number of distinct possible values of kk across all such ways.

给你三个正整数 aa、bb 和 ll(即 a,b,l>0a,b,l \gt 0)。

可以证明:总存在非负整数(即 ≥0\ge 0)kk、xx 和 yy,使得 l=k⋅ax⋅byl = k \cdot a^x \cdot b^y 成立。

你的任务是:求出所有满足该等式的方案中,kk 的不同可能取值的个数。

输入格式

The first line contains the integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The following tt lines contain three integers, aa, bb and ll (2≤a,b≤1002 \le a, b \le 100, 1≤l≤1061 \le l \le 10^6) — description of a test case.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

接下来的 tt 行每行包含三个整数 aa、bb 和 ll(2≤a,b≤1002 \le a, b \le 100,1≤l≤1061 \le l \le 10^6)—— 表示一个测试用例的描述。

输出格式

Output tt lines, with the ii-th (1≤i≤t1 \le i \le t) line containing an integer, the answer to the ii-th test case.

输出 tt 行,其中第 ii 行(1≤i≤t1 \le i \le t)包含一个整数,表示第 ii 个测试用例的答案。

输入输出样例

  • 输入#1

    11
    2 5 20
    2 5 21
    4 6 48
    2 3 72
    3 5 75
    2 2 1024
    3 7 83349
    100 100 1000000
    7 3 2
    2 6 6
    17 3 632043

    输出#1

    6
    1
    5
    12
    6
    11
    24
    4
    1
    3
    24

说明/提示

In the first test case, a=2,b=5,l=20a=2, b=5, l=20. The possible values of kk (and corresponding x,yx,y) are as follows:

  • Choose k=1,x=2,y=1k = 1, x = 2, y = 1. Then k⋅ax⋅by=1⋅22⋅51=20=lk \cdot a^x \cdot b^y = 1 \cdot 2^2 \cdot 5^1 = 20 = l.
  • Choose k=2,x=1,y=1k = 2, x = 1, y = 1. Then k⋅ax⋅by=2⋅21⋅51=20=lk \cdot a^x \cdot b^y = 2 \cdot 2^1 \cdot 5^1 = 20 = l.
  • Choose k=4,x=0,y=1k = 4, x = 0, y = 1. Then k⋅ax⋅by=4⋅20⋅51=20=lk \cdot a^x \cdot b^y = 4 \cdot 2^0 \cdot 5^1 = 20 = l.
  • Choose k=5,x=2,y=0k = 5, x = 2, y = 0. Then k⋅ax⋅by=5⋅22⋅50=20=lk \cdot a^x \cdot b^y = 5 \cdot 2^2 \cdot 5^0 = 20 = l.
  • Choose k=10,x=1,y=0k = 10, x = 1, y = 0. Then k⋅ax⋅by=10⋅21⋅50=20=lk \cdot a^x \cdot b^y = 10 \cdot 2^1 \cdot 5^0 = 20 = l.
  • Choose k=20,x=0,y=0k = 20, x = 0, y = 0. Then k⋅ax⋅by=20⋅20⋅50=20=lk \cdot a^x \cdot b^y = 20 \cdot 2^0 \cdot 5^0 = 20 = l.

In the second test case, a=2,b=5,l=21a=2, b=5, l=21. Note that l=21l = 21 is not divisible by either a=2a = 2 or b=5b = 5. Therefore, we can only set x=0,y=0x = 0, y = 0, which corresponds to k=21k = 21.

In the third test case, a=4,b=6,l=48a=4, b=6, l=48. The possible values of kk (and corresponding x,yx,y) are as follows:

  • Choose k=2,x=1,y=1k = 2, x = 1, y = 1. Then k⋅ax⋅by=2⋅41⋅61=48=lk \cdot a^x \cdot b^y = 2 \cdot 4^1 \cdot 6^1 = 48 = l.
  • Choose k=3,x=2,y=0k = 3, x = 2, y = 0. Then k⋅ax⋅by=3⋅42⋅60=48=lk \cdot a^x \cdot b^y = 3 \cdot 4^2 \cdot 6^0 = 48 = l.
  • Choose k=8,x=0,y=1k = 8, x = 0, y = 1. Then k⋅ax⋅by=8⋅40⋅61=48=lk \cdot a^x \cdot b^y = 8 \cdot 4^0 \cdot 6^1 = 48 = l.
  • Choose k=12,x=1,y=0k = 12, x = 1, y = 0. Then k⋅ax⋅by=12⋅41⋅60=48=lk \cdot a^x \cdot b^y = 12 \cdot 4^1 \cdot 6^0 = 48 = l.
  • Choose k=48,x=0,y=0k = 48, x = 0, y = 0. Then k⋅ax⋅by=48⋅40⋅60=48=lk \cdot a^x \cdot b^y = 48 \cdot 4^0 \cdot 6^0 = 48 = l.

在第一个测试用例中,a=2,b=5,l=20a=2, b=5, l=20。可能的 kk 值(及其对应的 x,yx,y)如下:

  • 选择 k=1,x=2,y=1k = 1, x = 2, y = 1。此时 k⋅ax⋅by=1⋅22⋅51=20=lk \cdot a^x \cdot b^y = 1 \cdot 2^2 \cdot 5^1 = 20 = l。
  • 选择 k=2,x=1,y=1k = 2, x = 1, y = 1。此时 k⋅ax⋅by=2⋅21⋅51=20=lk \cdot a^x \cdot b^y = 2 \cdot 2^1 \cdot 5^1 = 20 = l。
  • 选择 k=4,x=0,y=1k = 4, x = 0, y = 1。此时 k⋅ax⋅by=4⋅20⋅51=20=lk \cdot a^x \cdot b^y = 4 \cdot 2^0 \cdot 5^1 = 20 = l。
  • 选择 k=5,x=2,y=0k = 5, x = 2, y = 0。此时 k⋅ax⋅by=5⋅22⋅50=20=lk \cdot a^x \cdot b^y = 5 \cdot 2^2 \cdot 5^0 = 20 = l。
  • 选择 k=10,x=1,y=0k = 10, x = 1, y = 0。此时 k⋅ax⋅by=10⋅21⋅50=20=lk \cdot a^x \cdot b^y = 10 \cdot 2^1 \cdot 5^0 = 20 = l。
  • 选择 k=20,x=0,y=0k = 20, x = 0, y = 0。此时 k⋅ax⋅by=20⋅20⋅50=20=lk \cdot a^x \cdot b^y = 20 \cdot 2^0 \cdot 5^0 = 20 = l。

在第二个测试用例中,a=2,b=5,l=21a=2, b=5, l=21。注意 l=21l = 21 既不能被 a=2a = 2 整除,也不能被 b=5b = 5 整除。因此,我们只能取 x=0,y=0x = 0, y = 0,此时对应 k=21k = 21。

在第三个测试用例中,a=4,b=6,l=48a=4, b=6, l=48。可能的 kk 值(及其对应的 x,yx,y)如下:

  • 选择 k=2,x=1,y=1k = 2, x = 1, y = 1。此时 k⋅ax⋅by=2⋅41⋅61=48=lk \cdot a^x \cdot b^y = 2 \cdot 4^1 \cdot 6^1 = 48 = l。
  • 选择 k=3,x=2,y=0k = 3, x = 2, y = 0。此时 k⋅ax⋅by=3⋅42⋅60=48=lk \cdot a^x \cdot b^y = 3 \cdot 4^2 \cdot 6^0 = 48 = l。
  • 选择 k=8,x=0,y=1k = 8, x = 0, y = 1。此时 k⋅ax⋅by=8⋅40⋅61=48=lk \cdot a^x \cdot b^y = 8 \cdot 4^0 \cdot 6^1 = 48 = l。
  • 选择 k=12,x=1,y=0k = 12, x = 1, y = 0。此时 k⋅ax⋅by=12⋅41⋅60=48=lk \cdot a^x \cdot b^y = 12 \cdot 4^1 \cdot 6^0 = 48 = l。
  • 选择 k=48,x=0,y=0k = 48, x = 0, y = 0。此时 k⋅ax⋅by=48⋅40⋅60=48=lk \cdot a^x \cdot b^y = 48 \cdot 4^0 \cdot 6^0 = 48 = l。

输入解题思路,AI测评打分。不知道怎么写?

首页