B. Doremy‘s Perfect Math Class

传送门

题意:给你n个数,你可以对于数组中任意的两个数x,y进行以下操作:

如果x>y并且x-y不在数组中那么将x-y加入到数组中。

问你经过任意次操作,可以得到的最大的数组长度为多少?

思路: 

两个数不断相减,本质就是不断取模,(剩下的数就是大的数除以小的数的余数)参考更相减损术求最大公约数的原理。因此,如果没法继续减损,也就是说一直减损到两个数相等,这个数就是最大公约数。那么对于n个数的最大公约数,直接用最大值/最大公约数便是我们要得到的结果。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
int s[N];



int main()
{
	int t;
	cin>>t;
	for(int i =1;i<=t;i++)
	{
		cin>>n;
		int k=0;
		for(int j=1;j<=n;j++)
		{
			cin>>s[j];
			if(!k)k=s[j];
			else k=__gcd(k,s[j]);
		}
		cout<<s[n]/k<<endl;
	}
	
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值