Codility---CountFactors
|
Task description
A positive integer D is a factor of a positive integer N if there exists an integer M such that N = D * M. For example, 6 is a factor of 24, because M = 4 satisfies the above condition (24 = 6 * 4). Write a function:
that, given a positive integer N, returns the number of its factors. For example, given N = 24, the function should return 8, because 24 has 8 factors, namely 1, 2, 3, 4, 6, 8, 12, 24. There are no other factors of 24. Assume that:
Complexity:
|
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int N) {
// write your code in Java SE 8
int count = 0, i=1;
double max = Math.sqrt(N);
for(; i < max; i++) {
if(N % i ==0) {
count += 2;
}
}
if(i*i == N){
count++;
}
return count;
}
}
https://codility.com/demo/results/training5YTT4B-5NP/
Codility---CountFactors的更多相关文章
- Codility NumberSolitaire Solution
1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...
- codility flags solution
How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- *[codility]Peaks
https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...
- *[codility]Country network
https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...
- *[codility]AscendingPaths
https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...
- *[codility]MaxDoubleSliceSum
https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...
- *[codility]Fish
https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...
- *[codility]CartesianSequence
https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...
- [codility]CountDiv
https://codility.com/demo/take-sample-test/count_div 此题比较简单,是在O(1)时间里求区间[A,B]里面能被K整除的数字,那么就计算一下就能得到. ...
随机推荐
- 神经网络的 Delta 学习规则(learning rule)
1. δ 学习规则 1986 年,由认知心理学家 McClelland 和 Rumellhart 在神经网络训练中引入了 Δ 学习规则,该规则亦可称为连续感知器学习规则(与离散感知器学习规则相并行). ...
- misc子系统
跟着内核学框架-从misc子系统到3+2+1设备识别驱动框架 misc子系统在Linux中是一个非常简单的子系统,但是其清晰的框架结构非常适合用来研究设备识别模型.本文从misc子系统的使用出发, ...
- MacOS系统升级后,IDEA的SVN不好用的问题
最近给MacOS升级到10.13.2(High Sierra). 结果,发现IDEA的SVN不好用了. 提示如下: 查看IDEA的Subversion设置应该是这个样子的: 但是,设置后没有效 ...
- wpf控件设计时支持(1)
原文:wpf控件设计时支持(1) 这部分内容几乎是大家忽略的内容,我想还是来介绍一下. 本篇源码下载 1.属性元数据 在vs IDE中,在asp.net,winfrom等开发环境下,右侧的Proper ...
- 转:spring MVC HTTP406 Not Acceptable
springMVC框架下,ajax请求,在用json对象返回的时候,可以用如下的形式: response.setContentType("text/html;charset=UTF-8&qu ...
- 在.net MVC项目的区域中使用模板页
1.首先 在网站的区域目录areas下 的 区域目录下的 Views目录下新建一个 _ViewStart.cshtml文件 如下图所示: 2.在shared文件下新建一个视图作为Layout ...
- Python多线程 简明例子
综述 多线程是程序设计中的一个重要方面,尤其是在服务器Deamon程序方面.无论何种系统,线程调度的开销都比传统的进程要快得多. Python可以方便地支持多线程.可以快速创建线程.互斥锁.信号量 ...
- Cocos2d-x3.1颗粒使用
1.头 #include "cocos2d.h" USING_NS_CC; class WaterWaveDemo : public Layer { public: static ...
- N+1:创新点的设计
定义.公式.模型.算法的提出: 0. 如何进行抽象,如何定义数学表达式 二次衰减函数: f(z)=1z2 ⇒ f(z)=11+z2 噪声衰减因子: 对值域的要求,单调性的要求,必须是可调的: 2n1+ ...
- Myeclipse2014 激活 (包括方法和工具)
课程要求Myeclipse做各种各样的实验,对,当各种插头井.突然Myeclipse提示:使用过期,你可知道按那些个插件收了多少挫折么,怎能刚安好就用不了.可是又不想buy,所以就上网找破解咯,当中发 ...