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整除的数字,那么就计算一下就能得到. ...
随机推荐
- 一个自己犯的react错误
在看<react小书>高阶组件一节的时候,看到如下代码 import React, { Component } from 'react' export default (WrappedCo ...
- leetcode先刷_Valid Sudoku
我没有看到这个问题,这使其在现货需求数独,害怕一直没敢做.后来我发现原来的标题就是这么简单.推断现在只有数字全不符合的就可以了棋盘上的形势的要求. 是不是正确的三个周期..人是不能满意地看到每一行.每 ...
- win10 uwp 线程池
原文:win10 uwp 线程池 如果大家有开发 WPF 或以前的程序,大概知道线程池不是 UWP 创造的,实际上在很多技术都用到线程池. 为什么需要线程池,他是什么?如何在 UWP 使用线程池,本文 ...
- 区间树(segment tree)
区间树能够对保存的数据进行适当的预处理,以快速回复查询. 区间树常用于在一维数组的特定区间对查询进行快速回复.区间树的最典型也是最简单的应用就是求区间最小值的问题. 区间树的基本思路是,生成表示给定数 ...
- android点击屏幕隐藏小键盘
原文:android点击屏幕隐藏小键盘 fragment 下隐藏点击空白处隐藏小键盘 view.setOnTouchListener(new OnTouchListener() { @Overri ...
- EditText 详细信息(监听事件时,输入改变、透明背景、提示改变文字颜色、密文输入)
1.对EditText输入监视.给EditText 捆绑 addTextChangedListener 监控事件 能够. 2.EditText输入内容.密文显示: android:password=& ...
- Linking different libraries for Debug and Release builds in Cmake on windows?
问题叙述性说明: So I've got a library I'm compiling and I need to link different third party things in depe ...
- Eucalyptus企业云计算(建立能够和Amazon EC2兼容的云)
Eucalyptus是与一个在加利福尼亚大学的研究性项目,创建了一个使企业能够使用它们内部IT资源(包括服务器.存储系统.网络设备)的开源界面,来建立能够和Amazon EC2兼容的云. “Eucal ...
- debian8 root无法远程登录解决办法
改一下root 密码,应该就能本地登录了. 改/etc/ssh/sshd.conf,然后重启ssh就能远程登录了:PermitRootLogin yesPermitEmptyPasswords no
- v-charts显示标题
使用v-charts的时候,如果要显示标题需要以下操作 1. 加入:title props <ve-pie :title="chartTitle" :data="c ...