首页 > 其他分享 >CodeTON Round 1 D

CodeTON Round 1 D

时间:2022-09-22 16:13:50浏览次数:52  
标签:const cout int CodeTON Round 我们 define

D. K-good

我们考虑变式
我们设我们有一个k
(n-(k+1)k/2)%k=0
n=(k+1)
k/2+kp
2n=k(k+1+2p)
因为我们等式右边 k 和 k+1+2p 奇偶性不同 我们要求的就是k
而对于我们已知的就只有n
我们考虑对n因式分解 分成a*b a表示2的幂 b就表示成一个奇数
这样n也被分成了 奇偶两种不同的 我们分类讨论即可

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);

void solve() {
    int n,m=2;cin>>n;
    while(!(n&1))n>>=1,m<<=1;
    if(n>m)cout<<m<<endl;
    else if(n>1)cout<<n<<endl;
    else cout<<-1<<endl;
}
signed main(){
    fast
    int T;cin>>T;
    while(T--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:const,cout,int,CodeTON,Round,我们,define
From: https://www.cnblogs.com/ycllz/p/16719645.html

相关文章

  • Codeforces Round #813 (Div. 2) - D. Empty Graph
    构造Problem-D-Codeforces题意给\(n(1<=n<=10^5)\)个点,与权值\(a_i\),这\(n\)个点组成一个完全图,\(a_l\)与\(a_r\)连的边的权值为\(min(a_l,a_{l+1}...a_{r......
  • Codeforces Round #821 (Div. 2) D E
    E首先发现无论何时,每个位置上至多只会有一个球。原因:每个时刻每个球都会移动,所以移动到某个点的时间一定,自然出生时间也一定,显然不可能会有2个点出生时间相同。既然如......
  • Educational Codeforces Round 119 E
    E.ReplacetheNumbers开始想到了一个二分的做法好像是O(nlog)的后来才想了一下可以在两个数组之间反复横跳那我是不是像记忆化搜索一样记录一个路径即可我们记录f[i]......
  • Codeforces Round #818 (Div. 2) - D. Madoka and The Corruption Scheme
    思维+组合数学Problem-D-Codeforces题意有\(2^n\)个人进行锦标赛,编号1~\(2^n\),每一场输的人失去比赛资格,赢的人继续。Madoka可以选择他们进行的顺序,以及决定哪一......
  • Codeforces Round #821 (Div. 2) - D2. Zero-One (Hard Version)
    区间DPProblem-D2-Codeforces题意给一个长度为\(n(5<=n<=5000)\)的01串,每次操作可选择一个\(l,r(l<r)\),把\(s[l],s[r]\)反转。如果\(l+1==r\),花费为x,否......
  • Codeforces Round #807 (Div. 2) - D. Mark and Lightbulbs
    思维Problem-D-Codeforces题意给两个长度为\(n(3<=n<=2*10^5)\)的01串s与t,求最小操作次数,使s变成t;不存在则输出-1操作为:对于2<=i<=n-1,若\(s_......
  • Codeforces Round #820 (Div. 3) G. Cut Substrings
    DPProblem-G-Codeforces题意给一个长度为\(n(1<=n<=500)\)的主串s,一个长度为\(m(1<=m<=500)\)的模式串t,每次可以将当前的s中与t相同的子串变成一串"."(如......
  • Codeforces Round #821 (Div. 2) ABCD1
    A.ConsecutiveSumhttps://codeforces.com/contest/1733/problem/A题目大意:给定一个长度为n的数组a。最多可以执行k次以下操作:选择两个指数i和j,其中imodk=jmodk......
  • Codeforces Round #821(Div.2) (A-C) 题解
    CodeforcesRound#821(Div.2)(A-C)  A.ConsecutiveSum大致题意给定一组共n个数据,如果俩个数的下标在modk意义下同余,则可以交换a[I]和a[j] ,求操作后一段......
  • Codeforces Round #821 (Div. 2)(持续更新)
    Preface唉LOL打到一半被迫营业开打,感觉这算是第一次自己认真的在线打CF,以我的老年人手速感觉要罚时飞起了10:35开始打到12:10顶不住了睡觉去了,E大概看了个题感觉挺有意思的......