【2015-2016 XVI Open CupC】【暴力】Constant Ratio 等差数列前若干项恰好为n

C. Constant Ratio
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Given an integer n, find out number of ways to represent it as the sum of two or more integers ai with the next property: ratio ai / ai - 1 is the same positive integer for all possible i > 1.

Input

Input consists of one integer n (1 ≤ n ≤ 105).

Output

Print one integer — number of representations.

Examples
input
1
output
0
input
5
output
2
input
567
output
21
Note

In the first sample no such representation exists.

In the second sample there exist two representations:

  • 1 1 1 1 1, then q = 1.
  • 1 4, then q = 4.

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int casenum, casei;
int n;
bool check(int x, int y)
{
	int k = y / x;
	LL tmp = x;
	LL sum = x;
	while(1)
	{
		tmp = tmp*k;
		sum += tmp;
		if (sum == n)return 1;
		if (sum > n)return 0;
	}
}
int main()
{
	while(~scanf("%d",&n))
	{
		int ans = 0;
		for (int x = 1; x <= n; ++x)if(n%x==0)
		{
			for (int y = x; y <= n; y+=x)
			{
				if (check(x, y))++ans;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}
/*
【trick&&吐槽】
短的题一定要先读。水题大暴力。

【题意】
我们想找出一个数组a[],元素都为整数,个数至少为2个。
使得a[i]/a[i-1]对于i>1都为正整数

【类型】
暴力

【分析】
a[i]/a[i-1]对于i>1都为正整数
n还很小只有1e5.
我们直接暴力枚举a[1]和a[2],a[2]必须是a[1]的倍数
然后一直暴力查看和是否为n即可。
枚举a[1]、a[2]的复杂度是O(nlogn)
然后倍数倍增,当倍数>=k时,倍增次数均摊其实也不会超过10次。
于是整体的复杂度是(10nlogn),完全可以AC

【时间复杂度&&优化】
O(10nlogn)

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值