Gym 100917C Constant Ratio 数论+暴力

题目:

Description

standard input/output
Statements

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 - 1is 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.

Sample Input

Input

1

Output

0

Input

5

Output

2

Input

567

Output

21

Hint

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.

题目大意:给出一个等比数列(至少连个元素)的和n,要求公比q为整数,求满足要求的等比数列的个数。

题目思路:Sn=a1*(1-q^n)/(1-q),枚举q的值,判断a1是否为整数,比较暴力……

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<vector>
 5 #include<stdio.h>
 6 #include<stdlib.h>
 7 #include<queue>
 8 #include<math.h>
 9 #define INF 0x3f3f3f3f
10 #define MAX 1000005
11 #define Temp 1000000000
12
13 using namespace std;
14
15 int check(long long q,long long n)
16 {
17     long long a=q;
18     int ans=0;
19     while(n*(q-1)/(a-1) >= 1)
20     {
21         if(n*(q-1)%(a-1)==0 && n*(q-1)/(a-1)>=1 && n*(q-1)/(a-1)<n)//判断a1是否为整数,且满足要求
22             ans++;
23         a*=q;
24     }
25     return ans;
26 }
27
28 int main()
29 {
30     int n,sum;
31     sum=0;
32     scanf("%d",&n);
33     for(int i=1; i<n; i++)
34     {
35         if(n%i==0 && n/i>1)
36             sum++;
37     }
38     for(int i=2; i<n; i++)//枚举公比的值
39     {
40         sum+=check(i,n);
41     }
42     printf("%d\n",sum);
43     return 0;
44 }

时间: 2024-08-02 06:54:09

Gym 100917C Constant Ratio 数论+暴力的相关文章

数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

题目传送门 1 /* 2 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 3 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 4 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #in

UVA 617 - Nonstop Travel(数论+暴力枚举)

题目链接:617 - Nonstop Travel 题意:给定一些红绿灯,现在速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每一个速度,去判断可不可以,最后注意下输出格式即可 代码: #include <stdio.h> #include <string.h> #include <math.h> const double esp = 1e-6; int n, vis[105]; struct D { double l; int g, y,

ACM: Gym 100935G Board Game - DFS暴力搜索

Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 100935G Description standard input/outputStatements Feras bought to his nephew Saleem a new game to help him learning calculating. The game consists of a boar

Codeforces Gym 100002 C &quot;Cricket Field&quot; 暴力

"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description Once upon a time there was a greedy King who ordered his chief Architect to build a field for royal cricket inside his park. The King was so

Codeforces Gym 100513M M. Variable Shadowing 暴力

M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/M Description In computer programming, variable shadowing occurs when a variable declared within a certain scope has the same name as a variab

Codeforces Gym 100513G G. FacePalm Accounting 暴力

G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/G Description An owner of a small company FacePalm has recently learned that the city authorities plan to offer to small businesses to partic

codeforces Gym 100500C C. ICPC Giveaways 暴力

Problem C. ICPC GiveawaysTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description During the preparation for the ICPC contest, the organizers prepare bags full of giveaways for the contestants. Each bag us

codeforces 113C C. Double Happiness(数论+暴力)

题目链接: codeforces 113C 题目大意: 找出在[l,r]中的素数t,满足t=a2+b2(a,b为任意正整数),输出这种素数的数量. 题目分析: 首先筛出3?108所有为素数的奇数(偶数除了2都不可能是素数,为了节约内存) 然后枚举范围内的每一个数,判断这个数是不是4*k+1的形式的素数,如果是,那么这个数能够划分成a2+b2的形式,否则不行. AC代码: #include <iostream> #include <cstring> #include <cstd

Uva 10892 LCM Cardinality (数论/暴力)

题意:给出数n,求有多少组A,B的最小公约数为n; 思路:3000ms,直接暴力寻找,找到所有能把n整除的数 pi, 枚举所有pi 代码: #include <iostream> #include <cstdio> #include <vector> #define ll long long using namespace std; ll gcd(ll a,ll b) { if(b==0) return a; else return gcd(b,a%b); } int