POJ 3904 Sky Code(容斥原理)

FC游戏Hack实战:从零开始修改游戏数据 本文以《忍者神龟3》为例,详细介绍了从零开始进行FC游戏Hack的完整实战流程。通过使用FCEUX模拟器和调试器,结合“递减法”精准定位生命值内存地址,并利用十六进制编辑器修改关键指令,最终实现“无限生命”效果。文章旨在引导读者理解游戏数据修改的核心原理与操作技巧,重温经典的同时深入计算机程序运行机制。 阅读详情

Sky Code

Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraft. That is why he is preparing to steal the spacecraft of Petru. There is only one problem – Petru has locked the spacecraft with a sophisticated cryptosystem based on the ID numbers of the stars from the Milky Way Galaxy. For breaking the system Stancu has to check each subset of four stars such that the only common divisor of their numbers is 1. Nasty, isn’t it? Fortunately, Stancu has succeeded to limit the number of the interesting stars to N but, any way, the possible subsets of four stars can be too many. Help him to find their number and to decide if there is a chance to break the system. 

Input
In the input file several test cases are given. For each test case on the first line the number N of interesting stars is given (1 ≤ N ≤ 10000). The second line of the test case contains the list of ID numbers of the interesting stars, separated by spaces. Each ID is a positive integer which is no greater than 10000. The input data terminate with the end of file.
Output
For each test case the program should print one line with the number of subsets with the asked property.
Sample Input

4
2 3 4 5 
4
2 4 6 8 
7
2 3 4 5 7 6 8

Sample Output

1 
0 
34
题意:

问给n个数,问这n个数中可以做成多少个四元组使得四个数互质,注意每两个数不用两两互质

分析:

我们知道n个数总的可以组成的四元组的个数为C4nCn4

因为直接求四个数互质的四元组有多少个比较难求,因此我们转而求不互质的四元组有多少个,即公因数为d的(d>1)的四元组,然后最终用C4nCn4减去

那么不互质的四元组有多少个怎么求呢?

我们首先可以想到公因数为d那么d到底是几?它可以是任何大于1的数,所以我们从2开始枚举d

那么确定下了d后我们知道四元组中四个数如果gcd是d的话那么说明四个数的因数得含有的d,因此我们需要知道给定的n个数中到底有几个数它的因子有d,一旦我们能知道有多少个数因子含有d,那么我们就可以用组合数算出这样的四元组的个数,假设含有因数d的数字有cnt个,那么可以构成的四元组就有C4cntCcnt4个

这个cnt怎么求呢?

对于每个给定的数我们可以对其进行质因数分解,得到不同的质因数,然后利用二进制枚举所有不同的组合方式,得到因数,说明这个数包含了这个因数,那么包含这个因数的数字的个数就可以加1,我们可以用cnt数组记录,cnt[i]表示含有因子i的数有多少。

那么知道了每种gcd为d(d>1)的四元组个数了,总的加起来就可以了吗?

当然不是因为里面会有重复

举个例子我们会枚举公因数为2的,为3的,为6的四元组的个数而公因数为6的四元组中一定有公因数为2和3的四元组,因为6=2×3,所以造成了重复

为了解决这个问题才引出这道题的主要算法

容斥定理

当公因数d中含有奇数个不同的质因子的时候为加,而为偶数个不同的质因子的时候为减,因为正如上面例子,奇数的时候(从1开始只含一个质因子)作为开始,偶数的时候就会出现重复,这样使用容斥定理就能消除多加多减的影响。

而记录因数d含有多少个不同质因子在上面二进制枚举质因子组合的时候顺便记录下来就好了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e4+10;
int n,m;
int cnt[maxn];//cnt[i]记录所给数据中,含有因数i的个数有几个
int num[maxn];//num[i]记录所给数据中,因数i中含有几个不同素因子
ll c[maxn];//c[i]表示组合数C(i,4)
int prime[maxn];
void init(){
    for(ll i = 4; i < maxn; i++){
        c[i] = i * (i - 1) * (i - 2) * (i - 3) / 24;
    }
}
void divide(int n){
    int tot = 0;
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0){
            prime[tot++] = i;
            while(n % i == 0) n /= i;
        }
    }
    if(n > 1) prime[tot++] = n;//分解质因子
    for(int i = 1; i < (1<<tot); i++){//枚举质因子组合情况得到所有可能因子
        int tmp = 1;
        int sum = 0;
        for(int j = 0; j < tot; j++){
            if(i & (1 << j)){
                tmp *= prime[j];
                sum++;
            }
        }
        cnt[tmp]++;//说明数n包含tmp这种因子,所以个数+1
        num[tmp] = sum;//tmp这种因子内含有sum个不同质因子
    }
}
int main(){
    init();
    memset(num,0,sizeof(num));
    while(scanf("%d",&n) != EOF){
        memset(cnt,0,sizeof(cnt));
        for(int i = 0; i < n; i++){
            scanf("%d",&m);
            divide(m);//质因子分解统计相关数据
        }
        ll ans = 0;
        for(int i = 2; i < maxn; i++){
            if(cnt[i] >= 4){
                if(num[i] & 1) ans += c[cnt[i]];//因子i中含有的质因子数为奇数加
                else ans -= c[cnt[i]];//否则减
            }
        }
        printf("%lld\n",c[n]-ans);
    }
    return 0;
}
决策树简介/PPT 最近给我们组新生讲了决策树的相关知识,以下是所做的PPT,参考了网络资源。 阅读详情

相关推荐

【小白指南】如何将deepseek引入WPS\Word\Excel中去?

如何将deepseek引入WPS\Word\Excel中去?纯小白都能看的懂,一步步操作就能行

2503_90498422的博客 1万+

UVA10894 Save Hridoy【Ad Hoc】

It would have been great if all the banners with good words could inspire us all. Then we could only make large banners with good words on them to make this world beautiful. With all the good wishes o...

海岛Blog 615

手把手教你分析解决Innovus DRC Violation 和Antenna Effect Violation

数字IC后端设计培训教程之手把手教你分析解决Innovus DRC Violation 和Antenna Effect Violation

weixin_37584728的博客 2928

code[VS] 1048 石子归并

题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], 每次合并可以合并相邻的两堆石子,一次合并的代价为两堆石子的重量和w[i]+w[i+1]。问安排怎样的合并顺序,能够使得总合并代价达到最小。 输入描述 Input Description 第一行一个整数n(n 第二行n个整数w1,w2...wn  (wi 输出描述 

yuhao199555的博客 937

一文看懂—Agent多智能体协作

多智能体协作已成为AI应对复杂任务的关键范式,通过模拟人类团队分工,实现专业化、高效化和纠错能力。本文系统阐述了多智能体协作的核心概念(智能体分工、工作流编排、工具使用)、与产品规划的关联(任务拆解、错误处理、组织架构设计),以及典型应用场景(报告生成、客服工单、学习规划)。同时剖析了常见陷阱(循环卡死、信息失真、成本失控)及解决方案,并提供了实用工具模板(角色定义卡、工作流画布、成本仪表盘)。最后通过市场竞品分析和旅行规划两个实战案例,展示了多智能体协作的实际价值。该技术正推动AI从单点智能迈向系统智能,

lee006006的博客 1033

ESP32-P4实战:LVGL V9.4 PPA加速配置与性能对比

本文详细介绍了如何在ESP32-P4平台上配置LVGL V9.4的PPA硬件加速功能,通过启用PPA加速显著提升图形处理性能并降低CPU占用率。文章包含环境准备、配置步骤、性能对比及常见问题解决方案,帮助开发者高效利用ESP32-P4的PPA加速器优化嵌入式GUI应用。

rice5的博客 1189

Sky Code(POJ-3904)

Problem Description Stancu likes space travels but he is a poor software developer and will never be able to buy his own spacecraft. That is why he is preparing to steal the spacecraft of Petru. The...

Alex_McAvoy的博客 471

Matlab2024a安装教程

点击【下一步】。8.选择解压后的【MATLAB R2024a(64bit)】文件夹中【Crack】文件夹下的【licese.lic】,点击【打开】。

qq_64359046的博客 4795

哪个编程工具让你的工作效率翻倍?

智能的代码编辑器如Visual Studio Code (VS Code) 和 GitHub Copilot,通过提供自动补全、语法高亮、错误提示等功能,极大地简化了代码编写过程。例如,VS Code 拥有大量的插件,可以轻松添加需要的功能,而 GitHub Copilot 则通过人工智能驱动的编程助手,帮助开发人员更高效、更准确、更快地编写代码。

陈奕昆的博客 1300

电机瞬态分析基础(2):理想电机的基本假设和正方向规定

电机瞬态分析基础之理想电机假设条件和正方向规定

weixin_45670943的博客 1144

Hermes 教程 03:Skills 系统

摘要:Hermes Skills是一种自我改进机制,可将解决问题的经验保存为可复用技能文档。v0.13.0版本遵循agentskills.io开放标准,与Claude Skills互通。技能创建流程包括发现问题、创建技能文件、加载使用和优化更新四个阶段。系统提供技能检索和自维护机制(Curator),支持技能媒体路由和多种管理命令。内置技能涵盖开发调试、创意头脑风暴等场景,通过积累技能使Hermes更适应用户需求。

程序猿_三产 726

SkyCode AI CodeX GPT3 开源项目指南

SkyCode AI CodeX GPT3 开源项目指南 项目介绍 SkyCode AI CodeX GPT3 是一个多语言的开源编程大模型,它基于著名的GPT-3架构设计。此项目致力于简化编程任务,支持包括Java、JavaScript、C、C++、Python、Go以及Shell在内的多种主流编程语言。SkyCode独特之处在于其能够理解中文注释,极大地方便了中国开发者群体。该模型不仅能够完...

gitblog_00816的博客 590

Android CCodec (十七) 硬件解码调用分析-1(基于V4l2)

简单的分析V4L2DecodeComponent和其相关内容,后续针对解码调用单独分析。

给大佬递杯卡布奇诺的博客 6592

容斥原理:poj 3904 Sky Code

我们尝试从集合论的角度理解容斥三个圆圈和事件可以表示为推广到n个集合的容斥关系可以得到这样的关系:奇数加、偶数减例题一. poj 3904 Sky Code题目大意给一串数字,求解互质四元组的个数(注意不必两两互质)解题思路网上有很多代码,但是详细讲解的很少,这里结合笔者的思路详细论述一下解题思路,耐心一看。首先容易想到,想计算不互质的四元组的个数,再用总的减去,关键是怎样计数不互质四元组的个数??

Hacker_vision 1167

深度学习工具包 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")

计算机控制技术及应用

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

POJ3904 Sky Code【容斥原理】

题目链接: http://poj.org/problem?id=3904 题目大意: 给你N个整数。从这N个数中选择4个数,使得这四个数的公约数为1。求满足条件的 四元组个数。 解题思路: 四个数的公约数为1。并不代表四个数两两互质。比方(2,3,4,5)公约数为1,可是 2和4并不互质。从反面考虑。先求出四个数公约数不为1的情况个数,用总的方案...

aoe41606的博客 97

假人有限元模型

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

POJ 3904 Sky Code 容斥原理

POJ 3904 题意 :  求给定的n个数中4个数的最大公约数为1的组合数 刚开始看居然只有300不到的人A了,就认为可能不简单,原来做起来的话只是比较清楚的容斥原理。 首先要求出每一个数的素因子,然后对于求出的素因子进行组合,加到vis[i][j]上,表示由i个素因子组合成的数j的个数。 然后就是容斥原理,总的组合数为sum = n*(n-1)*(n-2)*(n-3)/24

JayYe的专栏 1641

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ3904 Sky Code 容斥原理 or 莫比乌斯反演

在做题的时候遇到了莫比乌斯反演 所以就想找个题目做做 POJ3904 题目大意: 给出n 以及 n 个数字 找到四个互质的数有多少种 即 求gcd(a,b,c,d)=1的情况数 可以用容斥原理 找到四个数不互质的情况 然后用总数减去这些情况 就是互质的 参考:https://blog.youkuaiyun.com/lianai911/article/details/47609075 四...

OneLine_的博客 320

POJ3904 Sky Code 容斥原理

这道题很容易想到用总的情况减去不互素的情况,需要统计不同素因子对应的数据个数,但这样会多算(比如2的因子减过一次,3的因子减过一次,这时6的情况(eg:6,12,18,24)就多减了一次),因此想到用容斥原理。问题的关键在于,怎么得到不同素因子组合对应的情况。附上大佬博客Orz:https://www.cnblogs.com/lmjer/p/9325754.html 这篇博客讲的很清楚,主要就是...

A confused programmer 393

POJ 3904 Sky Code 莫比乌斯反演 容斥原理

原题见POJ 3904给n个数,求其中四个数的gcd是1的情况有多少种。从反面考虑,算出gcd不是1的情况,总数取反即是结果。这是容斥原理的思想。当时在做POJ 1091的时候即是这样的想法。画一个vene图,每个集合表示最大公约数为k的情况数。 当k含有素数因子的平方项,如4,12,其实已经被2的情况数覆盖,不必再进行任何处理。只需考虑k是素数的一次方的乘积的情况。当素数个数为奇数个,如2,

Ugly Gardon 2409

POJ 3904 Sky Code 容斥原理

题目来源:POJ 3904 Sky Code 题意:选出最大公约数为1的四元组的方案 思路:容斥原理 总的方案C(n,4)减去t(1)+t(2)-t(3)+...+(-)^kt(k) t(i)表示四元组公因子的个数为i的方案数 #include #include #include using namespace std; const int maxn = 10010; typedef

嗯。 1217

POJ 3904 Sky Code (互素的四元组+容斥原理)

POJ 3904 Sky Code (互素的四元组+容斥原理) :http://poj.org/problem?id=3904 题目大意: 给定n个数据,求其中互素的四元组(两两可以不互素)的个数。 题目分析: 要想求互素的四元组的个数,我们可以先去求不互素的四元组的个数ans,然后所有可能的取法数C(n,4)(n个里面取4个的组合数公式)减去不互素的四元组的个数。 考虑到不互素的四元组

而濡木染 1303

POJ 3904-Sky Code 容斥原理

按照惯例,先附上题目链接http://poj.org/problem?id=3904这个题大体意思为给你一组数,让你4个一组,看有多少种组合,满足它们的公因子为1.先来说下这个题目有什么难点,一是组合数目的问题N≤1e5, 还好最多知道C(1e5, 4), long long int 应该够了二是查找哪些组合满足条件,假设我们遵奉"万物皆可暴力"大法,不停地枚举,直接C(n, 4),测评姬估计要T...

萌新也要搞算法 280

poj3904 Sky Code【容斥原理】

Sky Code Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1977   Accepted: 635 Description Stancu likes space travels but he is a poor software developer and

dxx_111的博客 761

poj3904 Sky Code 容斥原理

五六个小时才过~本题过的人很少,看起来还是比较难的,但是看到跟组合数目有关系的,就先想到了容斥原理,由于选出的四个数的约数只有1,如此不妨先对每个数进行素因子分解,用每个数的素因子再去重新组合成其它数,再应用容斥定理即可,可是想确实是想好了,可是就是敲不出来,尝试了三个多小时,最终还是没敲出来,没办法 可能刚接触数论 ,对一些特殊处理不是很熟悉,想不到 所以参考了别人的 一下,看到他跟我思路也是大

shaonianguai 990

POJ 3904 Sky Code (容斥原理)

http://poj.org/problem?id=3904 题意,给出n个数,问有多少组(a,b,c,d)公约数为1,注意并不一定两两互质!          总共情况: C(n , 4)             容斥原理应用,           以2为因子的数有a个,3为因子 的数有b个,6为因子的数有c个,           n个数不互质的四元组个数为C

老李2009 703
上一篇: Balanced Number HDU - 3709(数位DP)
下一篇: POJ 2429 GCD & LCM Inverse(Miller_Rabin大素数测试+Pollar_rho素因子分解)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值