2016 Al-Baath University Training Camp Contest-1 E
Description
ACM-SCPC-2017 is approaching every university is trying to do its best in order to be the Champion, there are n universities, the ith of them has exactly ai contestants. No one knows what is the official number of contestants in each team yet, this year organizers are planing to minimize number of teams participating in the contest but they still want every contestant to participate, so they should select a number k so that each team will consist of exactly k contestant from the same university. Every contestant will belong to one team exactly, and number of these teams is as minimum as possible. Your job is to help the organizers in their task by writing a program that calculates two integers k, the number of contestants in each team, and m, the minimum number of teams will participate. 1 ≤ n ≤ 1000, 1 ≤ ai ≤ 106
First line of input contains an integer T denotes number of test cases. Each test case contains two lines: the first line contains one integern denotes number of universities, while the second line contains n space-separated integers the ith of them denotes number of contestants from the ith university.
For each test case, print one line containing two integers: the first one is k, the size of each team, and the second one is m, the minimum number of teams from all universities according to the previous conditions.
2
3
5 15 10
4
4 6 8 12
5 6
2 15
题意:有n支队,每个队都有ai的队员,现在重新分配人数,每个队人数相同,且只有相同学校的才能组队,要求队伍数量最少
解法:相同学校的才能组队,也就是说每个队的人数必须都能整除ai,那么应该是求ai的gcd,队伍数量就是拿人数除以gcd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<bits/stdc++.h> using namespace std; int a[100000]; int main() { int n,m; int t; cin>>t; while (t--) { int num; int sum=0; cin>>n; cin>>a[1]; num=a[1]; sum+=a[1]; for ( int i=2;i<=n;i++) { //int num; cin>>a[i]; sum+=a[i]; num=__gcd(a[i],num); } cout<<num<< " " <<sum/num<<endl; } return 0; |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~