hdu 5778 abs

Problem Description
Given a number x, ask positive integer y2, that satisfy the following conditions:
1. The absolute value of y - x is minimal
2. To prime factors decomposition of Y, every element factor appears two times exactly.
 

Input
The first line of input is an integer T ( 1T50)
For each test case,the single line contains, an integer x ( 1x1018)
 

Output
For each testcase print the absolute value of y - x
 

Sample Input
5 1112 4290 8716 9957 9095
 

Sample Output
23 65 67 244 70
由于y质因数分解式中每个质因数均出现2次,那么y是一个完全平方数,设y=z*z,题目可转换成求z,使得每个质因数出现1次. 我们可以暴力枚举z,检查z是否符合要求,显然当z是质数是符合要求,由素数定理可以得,z的枚举量在logn级别 复杂度 O(\sqrt[4]{n}log\sqrt[2]{n}4nlog2n

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
ll Abs(ll x){
   if(x<0)  return -x;
   return x;
}
bool judge(ll x){
    for(ll i=2;i*i<=x;i++){//printf("%lld ",i);
        int ans=0;
        while(1){
            if(x%i==0){
                ans++;x/=i;
            }
            else break;
            if(ans>=2) return false;
        }
    }//printf("%I64d~~~\n",x);
    return true;
}
ll b[]={0,3,2,1,0,1,2,2,1,0};
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        ll n,i,j,ans=9999999999;
        bool flag=false;
        scanf("%I64d",&n);
        ll s=sqrt(n);
        i=s;j=s+1;
        //judge(1089);
        if(n<=9)
            ans=b[n];
        else
            while(1){
                if(!judge(i)) i--;
                else {
                    ans=min(ans,Abs(i*i-n));flag=true;
                }
                if(!judge(j)) j++;
                else{
                    ans=min(ans,Abs(j*j-n));flag=true;
                }
                if(flag) break;
            }//printf("%I64d %d %I64d %d\n",i,judge(i),j,judge(j));
        printf("%lld\n",ans);
    }
    return 0;
}


### HDU 滤波器设计方法与实现 滤波器的设计通常涉及信号处理领域中的理论基础和技术细节。以下是关于如何在高校(如HDU)环境中设计并实现滤波器的方法及相关资源。 #### 数字滤波器基础知识 数字滤波器可以分为两大类:FIR(有限脉冲响应)和IIR(无限脉冲响应)。这两种类型的滤波器各有优缺点,在实际应用中需根据需求选择合适的类型[^1]。 - **FIR滤波器**的特点是稳定性好,易于实现线性相位特性,适合于需要精确控制群延迟的应用场景。 - **IIR滤波器**则具有更高的效率,尤其对于高阶滤波器而言,其计算复杂度较低,但在某些情况下可能会引入非线性相位失真。 #### 设计工具与软件支持 Audacity 是一款开源音频编辑软件,它提供了简单的低通、高通以及带通滤波功能。通过设置特定频率参数(例如800Hz),用户可以在该平台上快速测试基本的滤波效果。然而,如果目标是对摩尔斯电码或其他加密信息进行解密,则可能还需要额外编写脚本来解析经过滤后的信号特征。 对于更复杂的自定义滤波器设计任务,MATLAB 或 Python (SciPy库) 常被推荐作为首选开发环境: - MATLAB 提供了一个全面的 Signal Processing Toolbox ,其中包含了多种经典算法用于构建不同类型及规格化的数字滤波器模型; - SciPy 的 `signal` 子模块同样具备强大的能力来模拟离散时间系统的传递函数行为,并允许开发者灵活调整各项系数直至满足预期性能指标为止。 #### 示例代码片段 - 使用Python创建Butterworth LPF & HPF组合 下面展示了一段利用Scipy library 构建巴特沃斯型二阶低通加高通串联结构的例子: ```python from scipy import signal import numpy as np def butter_bandpass(lowcut, highcut, fs, order=2): nyq = 0.5 * fs low = lowcut / nyq high = highcut / nyq b, a = signal.butter(order, [low, high], btype='band') return b, a fs = 1000.0 # Sample rate, Hz cutoff_low = 300 # Desired cutoff frequency of the low-pass filter, Hz cutoff_high = 800 # Desired cutoff frequency of the high-pass filter, Hz b,a = butter_bandpass(cutoff_low,cutoff_high ,fs) w,h = signal.freqz(b,a,worN=8000) freqs = w*fs/(2*np.pi) gain_db = 20 * np.log10(abs(h)) # Plotting section omitted here... ``` 此程序展示了如何基于指定采样率(fs),生成对应截止频点分别为300赫兹至800赫兹范围内的带通滤波器原型。最终可绘制幅频响应曲线图以便直观评估所得到的结果是否符合项目要求。 #### 结论 综上所述,无论是借助图形界面友好的应用程序还是深入编程实践探索高级定制选项,都有助于完成高质量的滤波器设计方案。具体采用哪种途径取决于个人偏好以及手头可用的技术条件等因素决定。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值