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之内,求多少个速度满足一路不遇到红灯. 思路:暴力每个速度,去推断可不能够,最后注意下输出格式就 ...
随机推荐
- 【Python】关于Python有意思的用法
开一篇文章,记录关于Python有意思的用法,不断更新 1.Python树的遍历 def sum(t): tmp=0 for k in t: if not isinstance(k,list): tm ...
- json格式数据 ,将数据库中查询的结果转换为json(方式2)
controller: /*** * 返回所有版本的信息,json的形式返回到前台 * @return */ @RequestMapping(value="/getAllVersion&qu ...
- Linux 抓包命令
可使用如下命令,在Linux系统上进行抓包命令 tcpdump -n -i eth0 tcp port and host 192.168.9.45 -w ./filename.cap 说明: eth0 ...
- Linux中如何设置java环境变量
这里介绍Linux下如何设置java环境变量. 工具/原料 Linux java环境变量 方法/步骤 1 查看java的安装路径 查看java执行路径 配置java环境变量 java的安装 ...
- 判定生死的心跳机制 --ESFramework 4.0 快速上手(07)
在Internet上采用TCP进行通信的系统,都会遇到一个令人头疼的问题,就是"掉线".而"TCP掉线"这个问题远比我们通常所能想象的要复杂的多 -- 网络拓扑 ...
- .Net Core Session验证码
1.验证码帮助类 namespace IdeaCore.Services.Common { public class ValidateCodeService : IValidateCodeServic ...
- [ An Ac a Day ^_^ ] UVALive 2635 Housing Complexes 二分图最大匹配
快要比赛了 看看原来做过的题 感觉这道题当时做的还是挺费劲的 所以发一下 题意: 一个土豪要建别墅 因为有的地区地方不够大 所以要拆屋子 每个地方的字母就是对应开发商的地盘 没有字母的就是自由土地 一 ...
- GetLastError() 返回值含义
[0]-操作成功完成.[1]-功能错误.[2]-系统找不到指定的文件.[3]-系统找不到指定的路径.[4]-系统无法打开文件.[5]-拒绝访问.[6]-句柄无效.[7]-存储控制块被损坏.[8]-存储 ...
- MyBatisNet 学习
SQL Maps Sql Maps是这个框架中最激动人心的部分,它是整个iBATIS Database Layer的核心价值所在.通过使用Sql Maps你可以显著的节约数据库操作的代码量.SQL M ...
- 【Loadrunner】初学Loadrunner——参数化设置(Table类型关联数据库)
参数化输入是Loadrrunner里面一个强大的功能,属于Loadrunner的高级使用技巧. 我们在登录系统的时候,需要输入一组定义的用户名和密码,比如有5个虚拟用户同时登陆系统,则这五个用户都用这 ...