Gym 100917C Constant Ratio 数论+暴力
题目:
Description
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
1
0
5
2
567
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是否为整数,比较暴力……
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#define INF 0x3f3f3f3f
#define MAX 1000005
#define Temp 1000000000 using namespace std; int check(long long q,long long n)
{
long long a=q;
int ans=;
while(n*(q-)/(a-) >= )
{
if(n*(q-)%(a-)== && n*(q-)/(a-)>= && n*(q-)/(a-)<n)//判断a1是否为整数,且满足要求
ans++;
a*=q;
}
return ans;
} int main()
{
int n,sum;
sum=;
scanf("%d",&n);
for(int i=; i<n; i++)
{
if(n%i== && n/i>)
sum++;
}
for(int i=; i<n; i++)//枚举公比的值
{
sum+=check(i,n);
}
printf("%d\n",sum);
return ;
}
Gym 100917C Constant Ratio 数论+暴力的更多相关文章
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
- Codeforces Gym 100203G G - Good elements 暴力
G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- Codeforces Gym 100342E Problem E. Minima 暴力
Problem E. MinimaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attac ...
- HDU 1333 基础数论 暴力
定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了. /** @Date : 2017-09-08 14:12 ...
- UVA 617 - Nonstop Travel(数论+暴力枚举)
题目链接:617 - Nonstop Travel 题意:给定一些红绿灯.如今速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每个速度,去推断可不能够,最后注意下输出格式就 ...
随机推荐
- 7、Struts2实现文件上传和下载
一.实现单个文件上传 1.创建如下web项目结构 2.在src下的com.action包下创建UploadAction.java package com.action; import java.io. ...
- ural 1356. Something Easier(数论,哥德巴赫猜想)
1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime num ...
- 17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行。请采用循环控制语句来实现。 (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和。) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行.请采用循环控制语句来实现. (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和.) 1 1 1 1 ...
- table可更改th大小的jQuery插件
(function ($) { $.fn.resizetable = function () { var tableObj = $(this); var inResizeRange = false; ...
- sql存储过程——名称 ****不是有效的标识符
转载自http://blog.csdn.net/xb12369/article/details/8202703 假设存储过程:proc_test create proc proc_test @Prod ...
- Linux内核协议栈 NAT性能优化之FAST NAT
各位看官非常对不起,本文是用因为写的,如果多有不便敬请见谅 代码是在商业公司编写的,在商业产品中也不能开源,再次抱歉 This presentation will highlight our ef ...
- SQL Server 2012中快速插入批量数据的示例及疑惑
SQL Server 2008中SQL应用系列--目录索引 今天在做一个案例演示时,在SQL Server 2012中使用Insert语句插入1万条数据,结果遇到了一个奇怪的现象,现将过程分享出来,以 ...
- Hibernate查询、连接池、二级缓存
Hibernate第三天: 1. 对象状态 2. session缓存 3. lazy懒加载 4. 映射 一对一对映射 组件/继承映射 目标: 一.hibernate查询 二.hibernate对连接池 ...
- JavaScript(3)—— 正则表达式
---恢复内容开始--- 正则表达式 这是写的正则表达式,正则表达式的点比较多,也比较细.所以有些地方我们得注意的比较多.正则表达式在JS中是很重要的一个部分,其中他的语法都得牢记.不过最好还是理解性 ...
- Windows进程间通信(中)
二.文件映射 文件映射(Memory-Mapped Files)能使进程把文件内容当作进程地址区间一块内存那样来对待.因此,进程不必使用文件I/O操作,只需简单的指针操作就可读取和修改文件的内容. W ...