【HDU - 5922】Minimum’s Revenge(思维,最小生成树变形)

题干:

There is a graph of n vertices which are indexed from 1 to n. For any pair of different vertices, the weight of the edge between them is the least common multiple of their indexes.

Mr. Frog is wondering about the total weight of the minimum spanning tree. Can you help him?

Input

The first line contains only one integer T (T≤100T≤100), which indicates the number of test cases.

For each test case, the first line contains only one integer n (2≤n≤1092≤n≤109), indicating the number of vertices.

Output

For each test case, output one line "Case #x:y",where x is the case number (starting from 1) and y is the total weight of the minimum spanning tree.

Sample Input

2
2
3

Sample Output

Case #1: 2
Case #2: 5

Hint

In the second sample, the graph contains 3 edges which are (1, 2, 2), (1, 3, 3) and (2, 3, 6). Thus the answer is 5.

题目大意:

给一个n个点的图,编号1~n,每两个点u,v之间都有连边,边权=lcm(u,v),求最小生成树的权值和。

解题报告:

一眼扫过去是,所有点都和1号点连边。简单证明一下:别对lcm进行公式的化简,既然每个点的编号都要至少被考虑一次(连边一条),考虑每个点的编号x对答案的影响,这个点不论和谁连边,那LCM肯定>=x,且另一个点取x的因子时可以取等,1是所有数的因子,所以和1连边,所以每个点都可以取等,所以都和1连边肯定是最小的。等差公式求个和就行了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int a[MAX],b[MAX],n;
int main()
{int T,iCase=0;cin>>T;while(T--) {cin>>n;printf("Case #%d: %lld\n",++iCase,1LL*n*(n+1)/2-1);}return 0 ;
}

 

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

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

相关文章

《操作系统真象还原》-阅读笔记(下)

第十一章 任意进程的页目录表第0~767个页目录项属于用户空间&#xff0c;指向用户页表。第768~1023个页目录项指向内核页表。每创建一个新的用户进程,就将内核页目录项复制到用户进程的页目录表&#xff0c;其次需要把用户页目录表中最后一个页目录项更新为用户进程自己的页目…

Apollo进阶课程㊱丨Apollo ROS深入介绍

原文链接&#xff1a;进阶课程㊱丨Apollo ROS深入介绍 ROS是一个强大而灵活的机器人编程框架&#xff0c;从软件构架的角度说&#xff0c;它是一种基于消息传递通信的分布式多进程框架。ROS本身是基于消息机制的&#xff0c;可以根据功能把软件拆分成为各个模块&#xff0c;每…

一步步编写操作系统 31 cpu的分支预测 下

让我们说说预测的算法吧。 对于无条件跳转&#xff0c;没啥可犹豫的&#xff0c;直接跳过去就是了。所谓的预测是针对有条件跳转来说的&#xff0c;因为不知道条件成不成立。最简单的统计是根据上一次跳转的结果来预测本次&#xff0c;如果上一次跳转啦&#xff0c;这一次也预…

【HDU - 5493】Queue(思维,贪心,线段树)

题干&#xff1a; NN people numbered from 1 to NN are waiting in a bank for service. They all stand in a queue, but the queue never moves. It is lunch time now, so they decide to go out and have lunch first. When they get back, they don’t remember the exa…

Apollo进阶课程㊲丨Apollo自动驾驶架构介绍

原文链接&#xff1a;进阶课程㊲丨Apollo自动驾驶架构介绍 自动驾驶硬件架构&#xff1a;一般采用激光雷达作为主要感知传感器&#xff0c;同时结合摄像头、GPS/IMU、毫米波雷达、超声波雷达等&#xff0c;以NVIDIA Drive PX2 或 Xavier作为主要计算平台&#xff0c;在工业PC机…

一步步编写操作系统 32 linux内核获取内存容量的方法

操作系统是计算机硬件的管家&#xff0c;它不仅要知道自己的安装了哪些硬件&#xff0c;还得给出有效得当的管理措施&#xff0c;按照预定的一套管理策略使硬件资源得到合理的运用。但管理策略只是逻辑上的东西&#xff0c;是操作系统自圆其说的一套管理资源的方法&#xff0c;…

【HDU - 5489】Removed Interval(离散化,权值线段树,思维,最长上升子序列)

题干&#xff1a; Given a sequence of numbers Aa1,a2,…,aNAa1,a2,…,aN, a subsequence b1,b2,…,bkb1,b2,…,bk of AA is referred as increasing if b1<b2<…<bkb1<b2<…<bk. LY has just learned how to find the longest increasing subsequence (LI…

Apollo进阶课程㊳丨Apollo平台的快速入门

原文链接&#xff1a;进阶课程㊳丨Apollo平台的快速入门 Apollo是向汽车行业及自动驾驶领域的合作伙伴提供一个开放、完整、安全的软件平台&#xff0c;帮助他们结合车辆和硬件系统&#xff0c;快速搭建一套属于自己的完整的自动驾驶系统。 上周阿波君为大家详细介绍了「进阶课…

一步步编写操作系统 33 利用bios中断0x15子功能0xe820获取内存

咱们先介绍0xE820子功能&#xff0c;这是最灵活的内存获取方式。 bios中断 0x15的子功能0xE820能够获取系统的内存布局&#xff0c;由于系统内存各部分的类型属性不同&#xff0c;bios就按照类型属性来划分这片系统内存&#xff0c;所以这种查询则呈迭代式&#xff0c;每次bio…

16.深度学习练习:Building your Recurrent Neural Network - Step by Step

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/Building your Recurrent Neural Network - Step by Step1 - Forward propagation for the basic Recurrent Neur…

【2019icpc徐州站】Random Access Iterator(概率dp,有坑,tricks)

题干&#xff1a; Recently Kumiko learns to use containers in C standard template library. She likes to use the std::vector very much. It is very convenient for her to do operations like an ordinary array. However, she is concerned about the random-access…

一步步编写操作系统 34 内核利用bios中断获取物理内存大小

接上文&#xff0c;另一个获取内存容量的方法是bios 0x15中断的子功能0xE801。 此方法虽然简单&#xff0c;但功能也不强大&#xff0c;最大只能识别4G内存&#xff0c;不过这对咱们32位地址总线足够了。稍微有点不便的是&#xff0c;此方法检测到的内存是分别存放到两组寄存器…

【HDU - 5777】domino(贪心)

题干&#xff1a; Little White plays a game.There are n pieces of dominoes on the table in a row. He can choose a domino which hasnt fall down for at most k times, let it fall to the left or right. When a domino is toppled, it will knock down the erect dom…

17.深度学习练习:Character level language model - Dinosaurus land

本文节选自吴恩达老师《深度学习专项课程》编程作业&#xff0c;在此表示感谢。 课程链接&#xff1a;https://www.deeplearning.ai/deep-learning-specialization/ 文章目录1 - Problem Statement1.1 - Dataset and Preprocessing1.2 - Overview of the model2 - Building blo…

Apollo进阶课程㊴丨Apollo安装过程概述

原文链接&#xff1a;进阶课程㊴丨Apollo安装过程概述 Apollo是一个自动驾驶的平台&#xff0c;推荐的参考运行环境为&#xff1a;ThinkPAD X240、CPU&#xff1a;i5 、四核 、内存 8G、 硬盘容量40G以上。 上周阿波君为大家详细介绍了「进阶课程㊳丨Apollo平台的快速入门」。 …

【HDU - 6574】Rng(概率,古典概型)

题干&#xff1a; Avin is studying how to synthesize data. Given an integer n, he constructs an interval using the following method: he first generates a integer r between 1 and n (both inclusive) uniform-randomly, and then generates another integer l betw…

UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)

继承、实现、依赖、关联、聚合、组合的联系与区别 分别介绍这几种关系&#xff1a; 继承 指的是一个类&#xff08;称为子类、子接口&#xff09;继承另外的一个类&#xff08;称为父类、父接口&#xff09;的功能&#xff0c;并可以增加它自己的新功能的能力&#xff0c;继…

CS231n(1):图片分类笔记与KNN编程作业

声明&#xff1a;本博客笔记部分为CS231n官网笔记&#xff0c;这里对其进行引用&#xff0c;在此表示感谢。 课程官网地址为&#xff1a;http://vision.stanford.edu/teaching/cs231n/syllabus.html 本次课程对应B站教学视频为&#xff1a; https://www.bilibili.com/video/av5…

【HDU - 6557】Justice(思维,模拟,套路,SETset)

题干&#xff1a; On the table there are n weights. On the body of the i-th weight carved a positive integer kiki , indicating that its weight is 12ki12ki gram. Is it possible to divide the n weights into two groups and make sure that the sum of the weight…

Apollo进阶课程㊵丨Azure仿真平台使用

原文链接&#xff1a;进阶课程㊵丨Azure仿真平台使用 Azure是一种灵活和支持互操作的平台&#xff0c;它可以被用来创建云中运行的应用或者通过基于云的特性来加强现有应用。它开放式的架构给开发者提供了Web应用、互联设备的应用、个人电脑、服务器、或者提供最优在线复杂解决…