【牛客 - 185A】无序组数 (思维,数学,因子个数)

题干:

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

给出一个二元组(A,B)
求出无序二元组(a,b) 使得(a|A,b|B)的组数
无序意思就是(a,b)和(b,a) 算一组.

输入描述:

第一行数据组数 T(1≤T≤10000)
接下来T行,每行两个正整数 A,B(1≤A,B≤10000)

输出描述:

共T行,每行一个结果

 

示例1

输入

复制

1
4 6

输出

复制

11

说明

样例解释:
二元组如下:
(1,1)(1,2)(1,3)(1,6)
(2,1)(2,2)(2,3)(2,6)
(4,1)(4,2)(4,3)(4,6)
共12组.
无序二元组如下:(1,1)(1,2)(1,3)(1,6)
(2,2)(2,3)(2,6)
(4,1)(4,2)(4,3)(4,6)
共11组

 

解题报告:

   题目要求无序对,我们先想象成有序对,然后再减去重复的,就是最终答案了。

   有序对很好求,先打表出每一个数的因子个数,然后a和b的因子数相乘,就是有序对的个数,然后减去他俩最大公约数的因子个数(也就是重复了一次的个数)(此处用组合数公式去算,也就是C(n,2)。),得到的就是答案了。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int d[100010];
int T;
int main(){for(int i=1;i<100010;i++)for(int j=i;j<100010;j+=i)d[j]++;scanf("%d",&T);for(;T--;){int a,b;scanf("%d%d",&a,&b);printf("%d\n",d[a]*d[b]-d[__gcd(a,b)]*(d[__gcd(a,b)]-1)/2);}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441673.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php万能查询用预,PHP 与 mysql

一、php 的 sql 注入攻击1.1、什么是 sql 注入攻击用户提交一段数据库查询代码&#xff0c;根据返回的结果&#xff0c;获得某些他想得到的数据。比如 &#xff1a;查询某个管理员是否存在&#xff0c;一般程序员会这么写$sql "select * from user where nameluluyii and…

php 判断radio选中哪个,jquery如何判断单选按钮radio是否选中

jquery判断单选按钮radio是否选中的方法&#xff1a;1、加载页面的时候获取id&#xff0c;代码为【var fs$("#"id).val()】&#xff1b;2、点击按钮的时候获取id&#xff0c;代码为【var id $(this).attr("id")】。本教程操作环境&#xff1a;windows7系统…

【qduoj】【超级楼梯进阶版】

题干&#xff1a; 描述 N级阶梯&#xff0c;人可以一步走一级&#xff0c;也可以一步走两级&#xff0c;求人从阶梯底端走到顶端可以有多少种不同的走法。 输入 一个整数n&#xff0c;代表台阶的阶数。 输出 求人从阶梯底端走到顶端可以有多少种不同的走法&#xff0c;输出结…

matlab在光学实验中的应用,matlab在光学实验中的应用

matlab在光学实验中的应用 《MATLAB》课程论文MATLAB 在光学实验中的应用姓名&#xff1a;学号&#xff1a;专业&#xff1a;班级&#xff1a;指导老师&#xff1a;学院&#xff1a;完成日期&#xff1a;1MATLAB 在波动光学中的应用(姓名&#xff1a;郑苗苗 12012241736 2012 级…

【HDU - 6016】Count the Sheep (思维,类似二分图)

题干&#xff1a; Altough Skipping the class is happy, the new term still can drive luras anxious which is of course because of the tests! Luras became worried as she wanted to skip the class, as well as to attend the BestCoder and also to prepare for test…

如何生成时间序列matlab,求助:在MATLAB里如何输入时间序列中的时间

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼function[logRS,logERS,V]RSana(x,n,method,q)%Syntax:[logRS,logERS,V]RSana(x,n,method,q)%____________________________________________%% Performs R/Sanalysis on a time series.%% logRS is thelog(R/S).% logERS is theEx…

【CF#192 A】Funky Numbers (二分,查找,二元组)

题干&#xff1a; As you very well know, this years funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two…

matlab考试试题,matlab-考试试题-

matlab-考试试题- MATLAB 考试试题 (1) 产生一个1x10的随机矩阵&#xff0c;大小位于( -5 5)&#xff0c;并且按照从大到小的顺序排列好&#xff01;(注&#xff1a;要程序和运行结果的截屏)答案&#xff1a;a10*rand(1,10)-5;bsort(a, descend )1.请产生一个100*5 的矩阵&…

【HDU - 1702 】ACboy needs your help again! (栈和队列,水题模拟)

题干&#xff1a; ACboy was kidnapped!! he miss his mother very much and is very scare now.You cant image how dark the room he was put into is, so poor :(. As a smart ACMer, you want to get ACboy out of the monsters labyrinth.But when you arrive at the g…

java中jframe不存在怎么办,java – 设置JFrame背景,为什么这不起作用?

打印加载图像的宽度(如果为-1)则图像未正确加载.img Toolkit.getDefaultToolkit().createImage("red.png");System.out.println(img.getWidth(null)); // check what it prints值得阅读Loading Images Using getResource上的Java Tutorial您可以根据图像位置尝试任何…

后盾网经典原创视频教程php,《后盾网经典原创视频教程:PHP》139集

目录0_1 后盾网_IIS环境下PHP开发环境安装0 后盾网_PHP集成环境安装视频教程1 PHP视频教程 PHP基础(一)2 PHP视频教程 PHP基础(二)3 PHP视频教程 PHP基础(三)4 PHP视频教程 数据类型(一)5 PHP视频教程 数据类型(二)6 PHP视频教程 数据类型(三)7 PHP视频教程 类型转换 外部变量8…

【HDU - 1022】Train Problem I (栈模拟,水题,思维)

题干&#xff1a; As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a proble…

【HDU - 1216 】Assistance Required (模拟,类似素数打表,不是素数问题!)

题干&#xff1a; After the 1997/1998 Southwestern European Regional Contest (which was held in Ulm) a large contest party took place. The organization team invented a special mode of choosing those participants that were to assist with washing the dirty d…

任意阶魔方阵matlab程序,【精品】任意阶魔方阵算法(c语言)

n阶幻方是由前n^2(n的2次方)个自然数组成的一个n阶方阵&#xff0c;其各行、各列及两条对角线所含的n个数的和相等。洛书就是最基本的33阶魔方阵&#xff0c;做出某种最恰当的决定&#xff0c;横竖都有3个格。 0的倒数 a&#xff0d;1可以对于 n 阶单位矩阵 e 以及同阶的方阵 a…

【HDU - 1302】The Snail (模拟,水题)

题干&#xff1a; A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each succe…

悟空php微信复制的东西在哪找,微信收藏的文件在哪?从哪里能看到?

现在的微信有很多的小功能&#xff0c;非常的方便实用&#xff0c;但是很多功能大家都不知道&#xff0c;今天&#xff0c;开淘网小编就来教教大家怎么使用微信的“我的收藏”功能。这个功能非常实用&#xff0c;而且收藏的源文件删除的话&#xff0c;我们从收藏里还是一样能用…

python批量打印机excel,python自动化办公系列03_单个以及批量处理excel文件

先贴上数据集&#xff0c;链接&#xff1a;https://pan.baidu.com/s/1ttv7NwbRmfVPcj2iBHTAfg提取码&#xff1a;zg5v下面是关于如何计算每个销售额以及总销售的代码。import osimport pandas as pdos.chdir("C:\\Users\\yuyuk\\data science\\data analysis and descript…

【OpenJ_Bailian - 2299 】Ultra-QuickSort (归并排序 或 离散化 + 树状数组)

题干&#xff1a; In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequ…

redis阻塞队列 java,Redis阻塞/非阻塞队列

非阻塞队列RPUSH key value [value ...]RPOP keyLPUSH key value [value ...]LPOP keyR/LPUSH都是后进先出操作&#xff0c;组合起来则是先进先出&#xff0c;属于非阻塞操作&#xff0c;即&#xff1a;不管有无找到指定键值都立即返回。阻塞队列RPUSH key value [value ...]BR…

*【CodeForces - 791B】Bear and Friendship Condition (图论,判断完全图,dfs乱搞或带权并查集)

题干&#xff1a; Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends.…