Comet OJ - Contest #8 神奇函数

 

 

题意:

 

 思路:

       首先我们打表观察得到,f(x)为 x分解质因数之后 ∏pi^(ti/2) 

    再分析可得,∑f(i)=n/(1*1)*1*只为1的个数+n/(2*2)*2*只为2的个数+... 

       但是结果超时。

            在进行分析可得,只为x的个数 就是phi(x)。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=b;i>=a;i--)
using namespace std;
#define ll long long
const int N=3e5+5;
ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int T;
ll n;
ll f[10000010],ans,sum;
int main()
{
    T=rd();
    while(T--)
    {
        ans=0;sum=0;
        n=rd();
        int p=sqrt(n);
        dep(i,2,p)
        {
            int x=i+i;
            f[i]=n/(1ll*i*i);
            while(x<=p)
            {    
                f[i]-=f[x];
                x+=i;
            }
            ans=ans+1ll*f[i]*i;
            sum+=f[i];
        }
        printf("%lld\n",ans+n-sum); 
    }
}
View Code

 

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=b;i>=a;i--)
using namespace std;
#define ll long long
const int N=1e7+5;
ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int prime[N+10],phi[N+10],num[N+10],flag[N+10],l=0;
void isprime()
{
    phi[1]=1;
    for(int i=2;i<=N;i++)
    {
        if(!flag[i]) 
        {
            prime[++l]=i;
            phi[i]=i-1; 
        }
        for(int j=1;j<=l;j++)
        {
            if(1ll*prime[j]*i>N) break;
            phi[i*prime[j]]=phi[i]*(i%prime[j]?prime[j]-1:prime[j]);
            flag[prime[j]*i]=1;
            if(i%prime[j]==0) break;
        }
    }
}
int T;
ll n;
ll f[10000010],ans,sum;
int main()
{
    isprime();
    T=rd();
    while(T--)
    {
        ans=0;sum=0;
        n=rd();
        int p=sqrt(n);
        dep(i,1,p)
        {
            int x=i+i;
            f[i]=n/(1ll*i*i);
            ans=ans+1ll*f[i]*phi[i];
        }
        printf("%lld\n",ans); 
    }
}
View Code

 

转载于:https://www.cnblogs.com/The-Pines-of-Star/p/11334828.html

# YOLOv5 🚀 requirements # Usage: pip install -r requirements.txt # Base ------------------------------------------------------------------------ gitpython ipython # interactive notebook matplotlib>=3.2.2 numpy>=1.18.5 opencv-python>=4.1.1 Pillow>=7.1.2 psutil # system resources PyYAML>=5.3.1 requests>=2.23.0 scipy>=1.4.1 thop>=0.1.1 # FLOPs computation torch>=1.7.0 # see https://pytorch.org/get-started/locally (recommended) torchvision>=0.8.1 tqdm>=4.64.0 # protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012 # Logging --------------------------------------------------------------------- tensorboard>=2.4.1 # clearml>=1.2.0 # comet # Plotting -------------------------------------------------------------------- pandas>=1.1.4 seaborn>=0.11.0 # Export ---------------------------------------------------------------------- # coremltools>=6.0 # CoreML export # onnx>=1.9.0 # ONNX export # onnx-simplifier>=0.4.1 # ONNX simplifier # nvidia-pyindex # TensorRT export # nvidia-tensorrt # TensorRT export # scikit-learn<=1.1.2 # CoreML quantization # tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos) # tensorflowjs>=3.9.0 # TF.js export # openvino-dev # OpenVINO export # Deploy ---------------------------------------------------------------------- # tritonclient[all]~=2.24.0 # Extras ---------------------------------------------------------------------- # mss # screenshots # albumentations>=1.0.3 # pycocotools>=2.0 # COCO mAP # roboflow # ultralytics # HUB https://hub.ultralytics.com
最新发布
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值