Finite or not?(CF-#483 DIV2-C)(数论——GCD)

35 篇文章 0 订阅

C. Finite or not?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given several queries. Each query consists of three integers ppqq and bb. You need to answer whether the result of p/qp/q in notation with base bb is a finite fraction.

A fraction in notation with base bb is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point.

Input

The first line contains a single integer nn (1n1051≤n≤105) — the number of queries.

Next nn lines contain queries, one per line. Each line contains three integers ppqq, and bb (0p10180≤p≤10181q10181≤q≤10182b10182≤b≤1018). All numbers are given in notation with base 1010.

Output

For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise.

Examples
input
Copy
2
6 12 10
4 3 10
output
Copy
Finite
Infinite
input
Copy
4
1 1 2
9 36 2
4 12 3
3 5 4
output
Copy
Finite
Finite
Finite
Infinite
Note

612=12=0,510612=12=0,510

43=1,(3)1043=1,(3)10

936=14=0,012936=14=0,012

412=13=0,13


首先恭喜杨哥哥在这次比赛中蓝名!!!,虽说有点(非常)妒忌,但是我也很开心,有人陪我打CF,还有人教我,

让我从黑名一步一步走出来,希望下一次就绿名。。。

题意:p/q   在b进制是否是一个  有限小数。

题解:这个题目有意思,

在杨哥哥的教导下,他说,首先对  分子分母约分,然后  再不断地对  b和q  /gcd(b,q);

主要看   q==1 证明有限,反之就说明  无限。

但是这样很很容易超时,  所以   b不断减少,减少它们间的差距来达到  优化。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define gcd __gcd               //350(杨哥哥过的时间)
/*inline ll gcd(ll a,ll b){     //390
  while(b^=a^=b^=a%=b);
        return a;
}*/
/*inline ll gcd(ll a,ll b){     //420
    return a%b==0?b:gcd(b,a%b);
}*/
/*inline ll gcd(ll x,ll y){     //620
    ll i,j;
    if(x==0)return y;
    if(y==0)return x;
    for(i=0;0==(x&1);i++)x>>=1;
    for(j=0;0==(y&1);j++)y>>=1;
    if(j<i)i=j;
    while(1){
        if(x<y)x^=y,y^=x,x^=y;
        if(0==(x-=y))return y<<i;
        while(0==(x&1))x>>=1;
    }
}*/
int main()
{
    ll T,p,q,b;
    scanf("%lld",&T);
    while(T--){
        scanf("%lld%lld%lld",&p,&q,&b);
        ll t=gcd(p,q);
        q/=t;
        t=b;
        while(q!=1){
            t=gcd(q,t);
            q/=t;
            if(t==1)break;
        }
        if(q==1){
            printf("Finite\n");
        }else{
            printf("Infinite\n");
        }
    }
    return 0;
}

有限创新速率(finite-rate-of-innovation)是指在一定时间内创新的速率有限。这个概念最早由Mathe Zibulevsky等人提出,并应用于信号处理中的稀疏表示算法。 在稀疏表示算法中,通常假设信号是以某些基向量的线性组合表示的,而稀疏表示算法的目标就是通过选择尽量少的基向量来近似原始信号。然而,如果信号的创新速率较高,即信号中出现的细节和特征的变化较快,那么传统的稀疏表示算法可能无法精确地捕捉到信号中的全部信息。 有限创新速率的概念是为了解决这个问题。它假设信号在一段时间内的变化相对较慢,并且引入了一种慢变化模型,即假设信号的创新速率是有限的。在这种情况下,可以通过在信号的表示中引入一些先验知识和约束条件,来提高稀疏表示的准确性。这些约束条件可以是基于信号本身的性质,也可以是来自外部领域知识的先验信息。 有限创新速率的概念在稀疏表示算法中被广泛应用,并且在信号处理和图像处理等领域取得了很好的效果。它提供了一种有效的方法来处理变化较快的信号,提高信号表示的精度和稳定性。同时,由于引入了先验知识和约束条件,这种方法也可以有效地减少所需的计算量和存储空间,提高算法的效率和实用性。 有限创新速率的概念在现代科学和工程中具有一定的重要性,它为我们理解和处理快速变化的信号提供了有益的思路和方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值