首页 > 小红的gcd
头像 Turgen
发表于 2026-01-30 00:52:46
观察样例大胆猜测:答案是 因为任意两个数的gcd一定有一个因子是总体的gcd,也就是这个数一定是总体的倍数,连续gcd后,最终的数必然都会变成全体的最大公约数,不可能比这个还小,因为gcd最小就能让一个数减少到全体的公约数,不会使得一个数比这个全体的公约数还要小,因此我们简单证明了这个答案是最小的, 展开全文
头像 Silencer76
发表于 2026-01-30 15:00:38
注意到 最少执行 遍题目所给操作,就可以让数组元素最小,和也最小。 import math n=int(input()) a=list(map(int,input().split())) for i in range(1,n): a[i]=math.gcd(a[i-1],a[i]) p 展开全文
头像 小男娘
发表于 2026-01-30 13:33:14
两行用分号可以一行 from math import gcd print(int(input()) * gcd(*map(int, input().split())))
头像 Eternal_ATRI
发表于 2026-01-30 14:16:48
# 曲线行驶 # 车压道路边缘线,扣100分,考试结束,成绩不合格。请不要下车,等待补考 from functools import reduce from math import gcd n=int( input( ) ) print( n*reduce( 展开全文
头像 刘森煜
发表于 2026-01-30 01:24:50
#include <iostream> #include <vector> using namespace std; long long gcd(long long a, long long b){ while(b!=0){ long long tem 展开全文
头像 Anon不是奶龙
发表于 2026-01-30 11:31:54
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; lon 展开全文
头像 bing糖雪狸
发表于 2026-01-30 12:33:59
#include<bits/stdc++.h> #define il inline #define endl '\n' using namespace std; #define pb push_back #define fastio \ ios::sync_with_stdio(fal 展开全文
头像 quchen666
发表于 2026-01-30 12:40:50
#include <bits/stdc++.h> using namespace std; const int N=3e5+10; const int mod = 998244353; typedef long long ll; typedef unsigned long long ul 展开全文
头像 ccl_aurora
发表于 2026-01-30 15:21:13
#include <iostream> #include<vector> #define ll long long using namespace std; ll gcd(ll a,ll b){ ll t; while(a%b!=0){ t= 展开全文
头像 冰原毛豆企鹅
发表于 2026-01-30 16:10:47
#include <stdio.h> long long gcd(long long a,long long b){ while(b!=0){ long long temp=b; b=a%b; a=temp; } 展开全文

等你来战

查看全部