当前位置:网站首页>【SSL集训DAY2】Sequence【数学】

【SSL集训DAY2】Sequence【数学】

2022-08-09 22:35:00 VL——MOESR

在这里插入图片描述

思路:

浅推一波我们发现就是把2n分成一个奇数*偶数,我们只需要把2的质因子全部除掉,然后把剩下的分解质因数

c o d e code code

#include<iostream>
#include<cstdio>

#define ll long long

using namespace std;

unsigned ll n;

int main() {
    
	cin>>n;
	if(n <= 2) {
     printf("-1"); return 0; }
	n *= 2;
	unsigned ll k = 1;
	while(n % 2 == 0) {
    
		n /= 2;
		k *= 2;
	}
	if(n == 1) {
    
		printf("-1");
		return 0;
	}
	for(unsigned ll i = 3; i * i <= n; i ++) {
    
		if(n % i == 0) {
    
			cout<<min(i, (k < n ? k : n));
			return 0;
		}
	}
	cout<<(k < n ? k : n);
	return 0;
} 
原网站

版权声明
本文为[VL——MOESR]所创,转载请带上原文链接,感谢
https://blog.csdn.net/liuziha/article/details/126196850