Sum Of Gcd HDU - 4676(莫队)

HDU 5381 The sum of gcd 询问区间内所有子区间的GCD和 [莫队算法] 预处理+莫队,需要抓住 gcd 的本质。 阅读详情

Given you a sequence of number a 1, a 2, …, a n, which is a permutation of 1…n.
You need to answer some queries, each with the following format:
Give you two numbers L, R, you should calculate sum of gcd(a[i], a[j]) for every L <= i < j <= R.
Input
First line contains a number T(T <= 10),denote the number of test cases.
Then follow T test cases.
For each test cases,the first line contains a number n(1<=n<= 20000).
The second line contains n number a 1,a 2,…,a n.
The third line contains a number Q(1<=Q<=20000) denoting the number of queries.
Then Q lines follows,each lines contains two integer L,R(1<=L<=R<=n),denote a query.
Output
For each case, first you should print “Case #x:”, where x indicates the case number between 1 and T.
Then for each query print the answer in one line.
Sample Input
1
5
3 2 5 4 1
3
1 5
2 4
3 3
Sample Output
Case #1:
11
4
0
把自己蠢哭了,智障去每次去dfs一个数的因子,直接预处理存起来不就好了嘛,预处理第一个询问居然直接去暴力,对自己无语啊。。。
优化版:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>
#include<vector>
#define N 20500
#define INF 10000000000
#define mod 1000000007
using namespace std;
typedef long long  ll;
vector<int> factor[20005];
int phi[N];
void init()
{
    for(int i=0;i<N;i++)
        phi[i]=i;
    for(int i=2;i<N;i++)
    {
        if(phi[i]==i)
        {
            for(int j=i;j<N;j+=i)
                phi[j]-=phi[j]/i;
        }
    }
    for(int i=1;i<=20000;i++)
        for(int j=i;j<=20000;j+=i)
        factor[j].push_back(i);

}
int block[N];
struct node
{
    int l,r;
    int index;
}query[N];
ll ans[N];
int a[N];
int cmp(node x1,node x2)
{
    if(block[x1.l]==block[x2.l])
        return x1.r<x2.r;
    return block[x1.l]<block[x2.l];
}
int cnt[N];
int curL,curR;
ll curAns;
void add(int x)
{
    for(int i=0;i<factor[x].size();i++)
        {
            int num=factor[x][i];
            curAns+=phi[num]*cnt[num];
            cnt[num]++;
        }
}
void sub(int x)
{
    for(int i=0;i<factor[x].size();i++)
        {
            int num=factor[x][i];
            cnt[num]--;
            curAns-=phi[num]*cnt[num];
        }
}
void work(int L,int R)
{
    while(curL<L)
    {
        sub(a[curL]);
        curL++;
    }
    while(curL>L)
    {
        curL--;
        add(a[curL]);
    }
    while(curR>R)
    {
        sub(a[curR]);
        curR--;
    }
    while(curR<R)
    {
        curR++;
        add(a[curR]);
    }
}
int main()
{
    init();
    int t,n;
    scanf("%d",&t);
    int cal=1;
    while(t--)
    {
        memset(cnt,0,sizeof(cnt));
        scanf("%d",&n);
        int limit=(int)sqrt(n);
        for(int i=1;i<=n;i++)
            block[i]=(i-1)/limit;
        for(int i=1;i<=n;i++)
            scanf("%d",a+i);
        int m;
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&query[i].l,&query[i].r);
            query[i].index=i;
        }
        sort(query+1,query+1+m,cmp);
        curAns=0;
        for(int i=query[1].l;i<=query[1].r;i++)
            add(a[i]);
        ans[query[1].index]=curAns;
        curL=query[1].l;
        curR=query[1].r;
        for(int i=2;i<=m;i++)
        {
            work(query[i].l,query[i].r);
            ans[query[i].index]=curAns;
        }
        printf("Case #%d:\n",cal++);
        for(int i=1;i<=m;i++)
            printf("%lld\n",ans[i]);
    }
    return 0;
}

智障的版本:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>
#include<vector>
#define N 20500
#define INF 10000000000
#define mod 1000000007
using namespace std;
typedef long long  ll;
vector<int> prime;
int phi[N];
void init()
{
    for(int i=0;i<N;i++)
        phi[i]=i;
    for(int i=2;i<N;i++)
    {
        if(phi[i]==i)
        {
            prime.push_back(i);
            for(int j=i;j<N;j+=i)
                phi[j]-=phi[j]/i;
        }
    }
}
int block[N];
struct node
{
    int l,r;
    int index;
}query[N];
int ans[N];
int a[N];
int cmp(node x1,node x2)
{
    if(block[x1.l]==block[x2.l])
        return x1.r<x2.r;
    return block[x1.l]<block[x2.l];
}
int gcd(int a,int b)
{
    return a%b==0?b:gcd(b,a%b);
}
int cnt[N];
int curAns,curL,curR;
int fac[100];
int e[100];
int k;
void getFac(int x)
{
    k=0;
    for(int i=0;prime[i]*prime[i]<=x;i++)
    {
        if(x%prime[i]==0)
        {
            fac[k]=prime[i];
            e[k]=0;
            while(x%prime[i]==0)
            {
                x/=prime[i];
                e[k]++;
            }
            k++;
        }
    }
    if(x>1)
    {
        fac[k]=x;
        e[k]=1;
        k++;
    }
}
int state;
void dfs(int cur,int temp)
{
    if(cur==k)
    {
        //cout<<temp<<endl;
        if(state==0)
        {
            cnt[temp]--;
            curAns-=phi[temp]*cnt[temp];
        }
        else
        {
            curAns+=phi[temp]*cnt[temp];
            cnt[temp]++;
        }
        return ;
    }
    dfs(cur+1,temp);
    int c=temp;
    for(int i=1;i<=e[cur];i++)
    {
        c*=fac[cur];
        dfs(cur+1,c);
    }

}
void dfs2(int cur,int temp)
{
    if(cur==k)
    {
        cnt[temp]++;
        return ;
    }
    dfs2(cur+1,temp);
    int c=temp;
    for(int i=1;i<=e[cur];i++)
    {
        c*=fac[cur];
        dfs2(cur+1,c);
    }

}
void work(int L,int R)
{
    while(curL<L)
    {
        state=0;
        getFac(a[curL]);
        dfs(0,1);
        curL++;
    }
    while(curL>L)
    {
        state=1;
        curL--;
        getFac(a[curL]);
        dfs(0,1);
    }
    while(curR>R)
    {
        state=0;
        getFac(a[curR]);
        dfs(0,1);
        curR--;
    }
    while(curR<R)
    {
        state=1;
        curR++;
        getFac(a[curR]);
        dfs(0,1);
    }
}
int main()
{
    init();
    int t,n;
    scanf("%d",&t);
    int cal=1;
    while(t--)
    {
        memset(cnt,0,sizeof(cnt));
        scanf("%d",&n);
        int limit=(int)sqrt(n);
        for(int i=1;i<=n;i++)
            block[i]=(i-1)/limit;
        for(int i=1;i<=n;i++)
            scanf("%d",a+i);
        int m;
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&query[i].l,&query[i].r);
            query[i].index=i;
        }
        sort(query+1,query+1+m,cmp);
        curAns=0;
        for(int i=query[1].l;i<=query[1].r;i++)
        {
            getFac(a[i]);
            dfs2(0,1);
            for(int j=i+1;j<=query[1].r;j++)
                curAns+=gcd(a[i],a[j]);
        }
        ans[query[1].index]=curAns;
        curL=query[1].l;
        curR=query[1].r;
        for(int i=2;i<=m;i++)
        {
            work(query[i].l,query[i].r);
            //cout<<curL<<" "<<curR<<endl;
            /*for(int i=1;i<=5;i++)
                cout<<cnt[i]<<" ";
            cout<<endl;*/
            ans[query[i].index]=curAns;
        }
        printf("Case #%d:\n",cal++);
        for(int i=1;i<=m;i++)
            printf("%d\n",ans[i]);
    }
    return 0;
}
固高GTS运动控制卡C#实战:三轴点胶机样本程序深度拆解(从跑通到落地优化) 最近接手一款三轴桌面式点胶机项目,核心控制模块选了固高GTS-400-PV运动控制卡——工业场景里的“老熟人”,稳定、脉冲输出精准,支持多轴联动,完全能满足点胶机的精度需求(±0.01mm)。但拿到固高官方提供的C#样本程序时,却犯了难:样本程序只实现了“三轴联动运动”的基础功能,既没有结合点胶机的核心需求(运动与出胶同步、路径自定义、急停处理),也没讲清关键参数(电子齿轮比、加速时间)的计算逻辑,新手照着跑通后,根本不知道怎么适配实际点胶场景。 阅读详情

相关推荐

iOS开发者必备:从越狱设备里提取IPA的三种方法(含Filza、iTools实战)

本文详细介绍了iOS开发者从越狱设备提取IPA文件的三种实用方法,包括使用Filza文件管理器、AFC2配合桌面工具以及命令行高级技术。内容涵盖环境准备、操作步骤和技术原理,帮助开发者高效获取应用包文件,适用于逆向工程、测试分析等场景。

weixin_28717969的博客 856

hdu4676 Sum Of Gcd

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4676题目大意:∑Ri=L∑Rj=i+1gcd(a[i],[j])\sum_{i=L}^{R}\sum_{j=i+1}^{R}gcd(a[i],[j])解题思路:用莫队算法优化,同时用到一个技巧:一个数n与一个集合中每个数的最大公约数的和=∑d∣nphi(d)∗num(d)=\sum_{d\mid n}p

单木的专栏 570

Pascal Context数据集实战:从安装到格式转换的完整指南

本文提供了Pascal Context数据集的完整实战指南,从安装配置到格式转换的详细步骤。Pascal Context是计算机视觉领域重要的语义分割数据集,包含540个精细标注类别。文章涵盖数据集下载、环境配置、预处理技巧和常见问题解决方案,帮助开发者高效利用这一数据集进行场景理解任务。

weixin_30216561的博客 618

HDU - 4676 Sum Of Gcd 莫比乌斯+莫队

题目链接 : 点这里 题意:给了一个数列a,然后给了一个区间[L, R],然后要求 sigma(gcd(i, j)), L <= i < j <= R。 解题方法: 令g(l, r) = sigma(gcd(i, j)), L <= i < j <= R.举个栗子,当a[L:R] = {4, 5, 8}时, 答案是1 + 1 + 4 = 6。由于最大公约数本身的定义,我们可以猜想多个数的gcd

I good vegetable a! 1042

华三模拟器实战:IPSec VPN穿越NAT的完整配置与调试(附常见问题排查)

本文详细解析了华三模拟器中IPSec VPN穿越NAT的完整配置与调试方法,包括基础环境准备、分步配置、ACL协调策略及高级故障排查。通过实战案例和关键参数解析,帮助网络工程师解决IPSec与NAT协同工作的典型问题,提升企业网络安全性。

weixin_33724046的博客 467

开发基于GDL235KBQ6开发板的IAP升级程序(HEX协议+串口空闲中断 + DMA接收数据)

使用GDL235kB开发板,实现串口iap升级程序的bootloader代码编写,app为led灯闪烁,并完成通信c代码

zhaozijuncc的博客 652

HDU 4676 Sum Of Gcd 【莫队 + 欧拉】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=4676 Sum Of Gcd Time Limit: 10000/5000 MS (Java/Others)Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 908Accepted Submission(s): ...

weixin_30686845的博客 145

每天一个优秀提示词学习收藏 - 文本创作篇(二)

宝子们,今天不藏私啦!我把这段时间四处搜罗、潜心钻研出来的文本创作 Prompt 提示词大礼包双手奉上,这可都是能让你的 AI 创作水平原地起飞的干货!走过路过不要错过,赶紧码住,开启你的 AI 创作进阶之旅吧!

2419

HDU 4676 Sum Of Gcd(分组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4676 题意:给出一个n的数列A,A的元素为1到n的一个排列。若干询问。每次查询区间[L,R],输出: 思路:设区间[L,R]内所有数字中有num[d]个数字有因子d,那么直观上想的话我们觉得答案应该加上: 因为这num[d]个数中每两个数的Gcd都有可能是d。但是这样又是不对的,比如区间...

weixin_33895516的博客 438

5、数据库基础概念与数据建模全解析

本文深入解析了数据库的基础概念,包括函数依赖、决定因素和多值依赖等关键依赖关系,同时探讨了数据建模的重要方法论,如IDEF1X、信息工程和陈方法。此外,还介绍了SQL Server管理工作室的图表功能,帮助用户进行数据库的可视化设计。通过本文,读者将掌握数据库设计的核心知识,为构建高效、可扩展的数据库系统奠定基础。

83

[系统安全] 一.什么是逆向分析、逆向分析基础及经典扫雷游戏逆向

娜璋AI安全之家于2020年8月18日开通,将专注于Python和安全技术,主要分享Web渗透、系统安全、CVE复现、威胁情报分析、人工智能、大数据分析、恶意代码检测等文章。真心想把自己近十年的所学所做所感分享出来,与大家一起进步。 系统安全系列作者将深入研究恶意样本分析、逆向分析、攻防实战等,通过在线笔记和实践操作的形式分享与博友们学习,希望能与您一起进步。第一篇文章先带领大家学习什么是逆向分析,然后详细讲解逆向分析的典型应用,接着通过OllyDbg工具逆向分析经典的游戏扫雷,再通过Cheat Engin

杨秀璋的专栏 2万+

HDU4676 Sum Of Gcd (数论 + 分块)

来看答案怎么求?  ∑i=LR∑j=i+1Rgcd(a[i],a[j])=∑i=LR∑j=i+1R∑d|gcd(a[i],a[j])ϕ(d)=∑dϕ(d)∑i=L,d|a[i]R∑j=i+1,d|a[j]R1 后一项就是[L,R]这段区间内有多少个d的倍数。  cnt[d][x]代表前x项中d的倍数的个数。  原式可化为  ∑i=LR∑j=i+1Rgcd(a[i],a

Dizzy的专栏 571

RAP 通用搜索实战:用 CDS 注解打造 Fiori Elements 的一体化检索体验

RAP应用中的通用搜索优化实践:通过CDS注解实现高效模糊匹配 摘要:本文介绍了在SAP RAP应用中优化列表搜索体验的方法。通过CDS注解配置通用搜索功能,用户无需指定字段即可在多字段中模糊匹配数据。关键实现包括:1)使用@Search.searchable启用全局搜索;2)通过@Search.defaultSearchElement标记核心搜索字段;3)利用@Search.fuzzinessThreshold设置容错阈值(0.7-1.0)处理拼写错误;4)使用@Search.ranking优化结果排序。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1404

Sum Of Gcd HDU 4676 (莫队)

Sum Of Gcd Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 986 Accepted Submission(s): 465 Problem Description Given you a sequence of numb...

king9666的博客 199

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【HDU4676】Sum Of Gcd(莫队+欧拉函数)

点此看题面 大致题意: 多组询问,求\(\sum_{i=L}^R\sum_{j=i+1}^Rgcd(i,j)\)。 推式子 这道题我们可以考虑,每个因数\(d\)被统计答案的次数,肯定与其出现次数有关。 设它出现次数为\(cnt_d\),则可以猜测答案为: \[\sum_{d=1}^nd\cdot C_{cnt_d}^2\] 这显然是错的,因为\(d\)虽作为公因数,却不一定是最大公约数。 所以就...

weixin_30352191的博客 142

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

[数论][莫队][莫比乌斯反演] hdu 4676 Sum Of Gcd

DescriptionDescription给定一个nn排列,qq次询问,每次询问∑L≤i<j≤Rgcd(ai,aj)\sum_{L\le i\lt j\le R}gcd(a_i,a_j)。SolutionSolution首先先推一推柿子:∑L≤i<j≤R(ai,aj)==∑L≤i<j≤R∑d|(ai,aj)d∑k|(aid,ajd)μ(k)∑L≤i<j≤R∑k|(ai,aj)∑d|kμ(kd)d

Vectorxj的博客 520

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

HDU - 4676 Sum Of Gcd(莫比乌斯反演+莫队)

传送门 题目大意 给出数组aaa是nnn的排列,给定l,rl,rl,r,求出区间[al,ar][a_l,a_r][al​,ar​]所有的∑i=lr∑j=lrgcd(ai,aj)\sum_{i=l}^{r} \sum_{j=l}^{r} gcd(a_i,a_j)∑i=lr​∑j=lr​gcd(ai​,aj​) 解题思路 在莫比乌斯反演那里学到了这个公式:n=∑d∣nφ(d)n=\sum_{d|n}\varphi(d)n=∑d∣n​φ(d) 代入后得:∑i=lr∑j=lr∑d∣gcd(i,j)φ(d)\su

Happig的博客 308

HDU 4676 Sum Of Gcd(莫队+莫比乌斯反演)

来看答案怎么求? ∑i=LR∑j=i+1Rgcd(a[i],a[j])=∑i=LR∑j=i+1R∑d|gcd(a[i],a[j])ϕ(d)=∑dϕ(d)∑i=L,d|a[i]R∑j=i+1,d|a[j]R1\sum_{i=L}^R\sum_{j=i+1}^Rgcd(a[i],a[j]) =\sum_{i=L}^R\sum_{j=i+1}^R\sum_{d|gcd(a[i],a[j])}\p

无限大な梦のあとの 何もない世の中じゃ 995

[莫比乌斯反演+莫队] HDU4676 Sum Of Gcd

反演的过程类似这题 ,得 ∑T=1nϕ(T) cnt[T]2 \sum_{T=1}^n \phi(T)\ cnt[T] ^2 cnt[T]cnt[T] 表示当前区间内是 TT 的倍数的数的个数。 因为有 cntcnt,每次直接求肯定不行,可以想到莫队。移动过程中每次暴力维护 cntcnt 即可。 复杂度理论很大,但实际上能过。#include<cstdio> #include<cmath>

Lynstery's blog 565

hdu 4676 Sum Of Gcd 莫队+phi反演

Sum Of Gcd 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4676 Description Given you a sequence of number a1, a2, ..., an, which is a permutation of 1...n. You need to answer some queries, each with ...

weixin_30567225的博客 107

[数论 反演 && 莫队] hdu4676 . Sum Of Gcd

假设我们知道一个区间内数字 ii 是否出现,另它为 bib_i 推一推 ∑i=1n∑j=1ngcd(i,j)×bi×bj\sum_{i=1}^{n}\sum_{j=1}^ngcd(i,j)\times b_i\times b_j=∑Tf(T)(∑T|ibi)2=\sum_Tf(T)(\sum_{T|i}b_i)^2其中f(T)=∑d|Td×μ(Td)f(T)=\sum_{d|T}d\times

CE玩家 651

HDU 5381 The sum of gcd 莫队暴力

链接 题解链接:http://www.cygmasot.com/index.php/2015/08/15/hdu_5381/ 题意: 给定n长的序列 下面n个数给出这个序列 m个询问 下面m行给出询问的区间。 对于一个询问,输出这个区间内的任意子段的gcd 和。 思路: 因为一个数的gcd只会不变或下降,下降一次至少减半,下降至多32次,所以处理出每个数连续相同的gcd的区间。 然后暴力跑莫队。 #pragma comment(linker, "/STACK:1

九野的博客 2636

hdu 5381 The sum of gcd 莫队 + DP

第一次用莫队A题。 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5381 #include #include #include #include #include #include #include #include #include using namespace std; const int MAXN = 10005;

NM的专栏 905

HDU - 5381 The sum of gcd 莫队

HDU - 5381 首先我们可以观察出从一个点开始的连续gcd最多只有log个, 因为gcd每次最少除2, 然后我们暴力莫队转移就好啦。 #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi...

weixin_30266885的博客 134
上一篇: 最小公倍数之和 V2 51Nod - 1190(莫比乌斯反演)
下一篇: Gcd表中的质数 51Nod - 1192 (莫比乌斯反演)
coldfresh
博客等级 码龄10年 107粉丝 405原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值