首页 > 其他分享 >Codeforces #889 div2 B

Codeforces #889 div2 B

时间:2023-07-30 15:12:21浏览次数:70  
标签:typedef 889 Codeforces long pair 倍数 区间 include div2

B. Longest Divisors Interval


做法:假设我们找到了一个最大区间[l, r],这个区间的长度为k,那么这个区间里有一个数必定是k的倍数(自己举个例子就能知道了),因此n也是k的倍数。那么我们再缩小一下区间长度,变为k - 1,这个区间可以是[l, r - 1],也可以是[l + 1, r],这其中必定有一个数是k - 1的倍数,而且这个数必定在原先的区间[l, r]中,我们又可以得到nk - 1的倍数,如此不断缩小区间直到区间长度为1。那么我们就可以得到n1、2、3 ... k的倍数,因此我们只需从1向上枚举,一旦n不能整除这个数就退出循环即可得到答案。

code
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
#include <string>
#include <set>
#define x first
#define y second
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, int> PDI;
typedef pair<double, double> PDD;
int dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

const int N = 100010;

LL n;

void solve()
{
	LL ans, i;
	cin >> n;
	for (i = 1, ans = 1; i <= n; i++, ans++)
		if (n % i != 0)break;

	cout << ans - 1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

标签:typedef,889,Codeforces,long,pair,倍数,区间,include,div2
From: https://www.cnblogs.com/dkdklcx/p/17591466.html

相关文章

  • Codeforces Round 889 (Div. 2) 题解
    \(6\)题只做出来\(1\)题,损失惨重A.DaltontheTeacher显然,答案一定和最初的不满意人数有关,所以输入的时候统计一下然后,将不满意的人的座位每两个人交换一次即可,交换次数就是答案如果不满意人数是奇数,那么答案还要加\(1\)时间复杂度\(O(n)\)(输入的复杂度)B.LongestD......
  • Codeforces Round 889 (Div. 1) 题解
    A1.Dual(EasyVersion)https://codeforces.com/contest/1854/problem/A1题意给定一个长度为\(n\)的序列\(a_1,a_2,\dots,a_n\),你可以做以下操作:选定两个下标\(i,j(1\leqi,j\leqn)\),\(i,j\)可以相同,然后\(a_i\leftarrowa_{i}+a_j\)。要求构造一种操作......
  • Round 889 Div.2 意识流简记。
    太丢人了!D2D狂吃6发罚时,D2C都不会!不过无所谓,反正老年选手就是打着玩。D2A.答案为\(\lceil\frac{\sum_{i=1}^n[a_i=i]}{2}\rceil\)。D2B.我不会啊,猜了一下只需要枚举\(\le2000\)的,莫名其妙过了。D2C1/C2.不会。D2D.考虑动态维护前\(i\)个能凑出的数的集合,适时......
  • Codeforces Round 105 (Div. 2) - D. Bag of mice DP 或 记忆化搜索 求概率
    D.Bagofmice题意待补充~思路可利用DP或者记忆化搜索求解本问题,实际上这两个方法等价。当\(w=0\)时必输当$w\ne0$但$b=0$时必赢剩下的情况,先考虑一个问题:赢的局面是怎么构成的?代码记忆化搜索//>>>Qiansui#include<bits/stdc++.h>#definelllong......
  • Educational Codeforces Round 152 (Rated for Div. 2)
    传送阵T1MorningSandwich题目大意\(t\)个测试,每个测试给三个正整数\(b,c,h\),分别表示面包和两种馅料的个数,每两个面包之间必须放一个馅料,问最多能摆几层?思路我们发现\(c,h\)所表示的两种馅料其实相差不大,所以我们可以分两种情况\(a>c+h\)因为开头总是面包,所以要+......
  • Codeforces Round 888 (Div. 3)
    CodeforcesRound888(Div.3)T1​ 思路:直接模拟。T2​思路:首先记录原始数组的奇偶性,然后将奇数、偶数分为不同两组进行排序,然后再根据原数组的奇偶性按顺序填入奇数偶数,最后判断整个数组是否非递减。T3思路:我们已知开始在\(a_1\),最后在\(a_n\)。那么当\(a_1\ne......
  • Educational Codeforces Round 152 (Rated for Div. 2) 题解
    \(6\)题做出来\(3\)题,这一次的D题没能复刻上一次Round888Div.3最后几分钟AC的奇迹A.MorningSandwich大水题,5min时间4min都在翻译题面直接拿\(b\)和\(c+h\)进行比较分类讨论即可单次操作时间复杂度\(O(1)\)B.Monsters首先有一个特别显然、复杂度特别高的......
  • Educational Codeforces Round 152 (Rated for Div. 2)记录
    A.MorningSandwich#include<cstdio>#include<algorithm>#include<cmath>#include<vector>#include<string.h>#include<set>#include<string>#include<map>#include<iostream>#include<queue......
  • Educational Codeforces Round 76 (Rated for Div. 2)
    EducationalCodeforcesRound76(RatedforDiv.2)A-TwoRivalStudents思路:最多可加x个距离,且最后的距离不能超过n-1#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128typedefpair<int,int>PII;typedefpair<string,......
  • Educational Codeforces Round 152 A~D
    A#include<bits/stdc++.h>#defineendl'\n'#defineiosios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)usingnamespacestd;typedefpair<int,int>PII;constintN=2e5+10;constintMOD=1e9+7;intT;vo......