hdu 3939 Sticks and Right Triangle 求<=N的素勾股数的个数 容斥原理

本文探讨了如何在无限长的棍子上切割三个整数长度的子段以形成直角三角形的问题。通过数学算法确定了在特定长度限制下可以形成的直角三角形的数量。

不会做  直接贴

Problem Description
We have a stick with infinite length. Now we want to cut 3 sub-sticks with length x, y, z which is not large than L to form a right triangle. With unknown reasons we assume that x, y, z are all integers and satisfy that x, y, z are all co-primed each other. We want to know how many right triangles are there exist under our constraints
 

Input
The first line of input is an integer T (T<=5) indicating the number of test cases.
Each case contains a single integer L (L<=1,000,000,000,000).
 

Output
For each test case output a single integer in one line, indicating the number of right triangles.
 

Sample Input
1 5
 

Sample Output
1
Hint
In our test case, we could find a right triangle (3,4,5) which satisfy 3,4,5<=5 and gcd(3,4)=1,gcd(3,5)=1,gcd(4,5)=1.

//

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#define MAXN 1000000


using namespace std;


int pri[MAXN+10],pri_num,tab_phi[MAXN+10];
bool temp[MAXN+10];
int T,num,Dec[20];
long long ans,n;


void print_prime()
{
    pri_num=0;
    for(int i=2;i<MAXN;i+=2) temp[i]=1;
    pri[pri_num++]=2;
    tab_phi[2]=1;
    tab_phi[1]=1;
    for(int i=3;i<MAXN;i+=2)
    {
        if(!temp[i]) pri[pri_num++]=i,tab_phi[i]=i-1;
        for(int j=0;j<pri_num&&i*pri[j]<MAXN;j++)
        {
            temp[i*pri[j]]=1;
            if(i%pri[j]==0) {tab_phi[i*pri[j]]=tab_phi[i]*pri[j];break;}
            else tab_phi[i*pri[j]]=tab_phi[i]*(pri[j]-1);
        }
        if((((i+1)>>1)&1)==0) tab_phi[i+1]=tab_phi[(i+1)>>1]<<1;
        else  tab_phi[i+1]=tab_phi[(i+1)>>1];
    }
}


void prime_dec(int a)
{
    num=0;
    if(!temp[a]) {Dec[num++]=a; return;}
    for(int i=0;i<pri_num&&a>1;i++)
    {
        if(a%pri[i]==0)
        {
            Dec[num++]=pri[i];
            while(a%pri[i]==0)
            {
                a/=pri[i];
            }
            if(a>1&&(!temp[a])) {Dec[num++]=a; return;}
        }
    }
}


int dfs(int k,int l,int s,int a)
{
    if(k==num)
    {
        if(l&1) ans-=a/s;
        else ans+=a/s;
        return 0;
    }
    dfs(k+1,l,s,a);
    dfs(k+1,l+1,s*Dec[k],a);
    return 0;
}


int main()
{
    print_prime();
    cin>>T;
    while(T--)
    {
        ans=0;
        scanf("%I64d",&n);
        int m=(int)sqrt(n+0.0);
        for(int i=m;i>0;i--)
        {
            int p=(int)sqrt(n-(long long)i*i+0.0);
            if(i&1)
            {
                prime_dec(i);
                if(i<=p) dfs(0,0,1,i>>1);
                else dfs(0,0,1,p>>1);
            }
            else
            {
                if(i<=p) ans+=tab_phi[i];
                else  { prime_dec(i); dfs(0,0,1,p); }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}




【四轴飞行器】非线性三自由度四轴飞行器模拟器研究(Matlab代码实现)内容概要:本文围绕非线性三自由度四轴飞行器模拟器的研究展开,重点介绍基于Matlab代码实现的四轴飞行器动力学建模与仿真方法。研究构建了考虑非线性特性的飞行器数学模型,涵盖姿态动力学与运动学方程,实现了三自由度(滚转、俯仰、偏航)的精确模拟。文中详细阐述了系统建模过程、控制算法设计思路及仿真结果分析,帮助读者深入理解四轴飞行器的飞行动力学特性与控制机制;同时,该模拟器可用于算法验证、控制器设计与教学实验。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的高校学生、科研人员及无人机相关领域的工程技术人员,尤其适合从事飞行器建模、控制算法开发的研究生和初级研究人员。; 使用场景及目标:①用于四轴飞行器非线性动力学特性的学习与仿真验证;②作为控制器(如PID、LQR、MPC等)设计与测试的仿真平台;③支持无人机控制系统教学与科研项目开发,提升对姿态控制与系统仿真的理解。; 阅读建议:建议读者结合Matlab代码逐模块分析,重点关注动力学方程的推导与实现方式,动手运行并调试仿真程序,以加深对飞行器姿态控制过程的理解。同时可扩展为六自由度模型或加入外部干扰以增强仿真真实性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值