D Staircase Sequences
题意:
给你一个和sum。问你是否可以拆成公差为1的等差数列。
求:
最多可以拆成多少个。
思路:
- 这题猜出来的。就是求因数个数。(
偶数的因子不可以
) - 最后记得答案*2.
反思:
2020-1-31发现,猜得不严谨。有点对不起读者,所以特地来补充完整。
题目要求:
- 等差数列且前n项和为sum
- 公差d=1
过程
- 假设区间的左右端点是a和b。那么就可以表示成 [ a , b ] [a,b] [a,b]
- s u m = ( b − a + 1 ) ( a + b ) 2 sum = \frac{ (b-a+1)(a+b) }{2} sum=2(b−a+1)(a+b) (项数* (首项+末项) 等差数列求和公式)
- 为了满足题目要求2,那么 ( b − a + 1 ) (b-a+1) (b−a+1) 和 ( a + b ) (a+b) (a+b) 不能同时都是偶数
- (一个代表区间长度,一个代表首项+末项,eg:1,2,3,4,无论怎样都构造不出来)又或者(2,3,4,5)
- 题目问的是:有多少种可能。那么不就是求sum有多少个奇因子吗
AC
/*
皮卡丘冲鸭!
へ /|
/\7 ∠_/
/ │ / /
│ Z _,< / /`ヽ
│ ヽ / 〉
Y ` / /
イ● 、 ● ⊂⊃〈 /
() へ | \〈
>ー 、_ ィ │ //
/ へ / ノ<| \\
ヽ_ノ (_/ │//
7 |/
>―r ̄ ̄`ー―_
*/
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
const int N = 2e5+10;
const int M = 1e5;
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll x;
cin>>x;
vector<int>prime, prime_num;
ll ans = 1;
for(int i = 2; i <= x/i; i ++ ){
if(x%i==0){
prime.pb(i);
ll cnt = 0;
while(x%i==0)x/=i,cnt++;
// debug(i);
// debug(cnt);
// if(i!=2)ans+=cnt*2;
if(i!=2) ans*=(cnt+1);
}
}
if(x>2)ans*=2;
// ans+=2;
cout<<ans*2<<endl;
return 0;
}