Tasks Details
easy
1.
CountFactors
Count factors of given number n.
Task Score
100%
Correctness
100%
Performance
100%
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:
int solution(int N);
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.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..2,147,483,647].
Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
Solution
Programming language used C++
Time spent on task 19 minutes
Notes
not defined yet
Task timeline
Code: 13:52:41 UTC,
java,
autosave
Code: 13:53:18 UTC,
cpp,
autosave
Code: 13:53:36 UTC,
cpp,
autosave
Code: 13:54:01 UTC,
cpp,
autosave
Code: 13:54:32 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if(sqrt(N) ==)
}
}
Code: 13:54:43 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if(sqrt(N) == 0){
}
}
}
Code: 13:56:23 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if(sqrt(N)% == 0){
}
}
}
Code: 13:56:34 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if(sqrt(N) %2 == 0){
}
}
}
Code: 13:56:45 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if(sqrt(N) % 1 == 0){
}
}
}
Code: 13:57:08 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if(/i == 0)
}
}
Code: 13:57:19 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=0; i<sqrt(N) ; i++){
if( %i == 0)
}
}
Code: 13:57:30 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=; i<sqrt(N) ; i++){
if( N %i == 0)
}
}
Code: 13:57:44 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N) ; i++){
if( N %i == 0)
}
}
Code: 13:58:00 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N %i == 0)
}
}
Code: 13:58:31 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
sqrt(N)
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N%i == 0){
count++;
}
}
}
Code: 13:59:00 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N%i == 0){
count++;
}
}
if(sqrt(N) )
}
Code: 13:59:19 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N%i == 0){
count++;
}
}
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Code: 13:59:31 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N%i == 0){
count++;
}
}
count = count*2;
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Analysis
Compile error
func.cpp: In function 'int solution(int)': func.cpp:20:16: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator%' if(sqrt(N) % 1 == 0){ ~~~~~~~~^~~
Code: 13:59:38 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N%i == 0){
count++;
}
}
count = count*2;
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Code: 14:00:52 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i<sqrt(N); i++){
if( N%i == 0){
count++;
}
}
count = count*2;
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Code: 14:01:11 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count++;
}
}
count = count*2;
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Code: 14:01:23 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count = count*2;
}
}
count = count*2;
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Code: 14:01:33 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(sqrt(N) % 1 == 0){
count++;
}
return count;
}
Code: 14:01:48 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Analysis
Compile error
func.cpp: In function 'int solution(int)': func.cpp:21:17: error: no matching function for call to 'pow(int&)' if(pow(sqrtN) == N){ ^ In file included from /usr/include/math.h:83:0, from /opt/lang/gcc/include/c++/6.2.0/cmath:45, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:41, from func.cpp:2: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:153:16: note: candidate: double pow(double, double) __MATHCALL_VEC (pow,, (_Mdouble_ __x, _Mdouble_ __y)); ^~~ /usr/include/x86_64-linux-gnu/bits/mathcalls.h:153:16: note: candidate expects 2 arguments, 1 provided In file included from /opt/lang/gcc/include/c++/6.2.0/valarray:587:0, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:95, from func.cpp:2: /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:563:92: note: candidate: template<class _Tp> std::_Expr<std::_BinClos<std::_Pow, std::_Constant, std::_ValArray, _Tp, _Tp>, _Tp> std::pow(const _Tp&, const std::valarray<_Tp>&) /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:563:92: note: template argument deduction/substitution failed: func.cpp:21:17: note: candidate expects 2 arguments, 1 provided if(pow(sqrtN) == N){ ^ In file included from /opt/lang/gcc/include/c++/6.2.0/valarray:587:0, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:95, from func.cpp:2: /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:561:95: note: candidate: template<class _Tp> std::_Expr<std::_BinClos<std::_Pow, std::_ValArray, std::_Constant, _Tp, _Tp>, _Tp> std::pow(const std::valarray<_Tp>&, const _Tp&) /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:561:95: note: template argument deduction/substitution failed: func.cpp:21:17: note: mismatched types 'const std::valarray<_Tp>' and 'int' if(pow(sqrtN) == N){ ^ In file included from /opt/lang/gcc/include/c++/
Code: 14:02:04 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int )sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Code: 14:02:07 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Analysis
Compile error
func.cpp: In function 'int solution(int)': func.cpp:21:17: error: no matching function for call to 'pow(int&)' if(pow(sqrtN) == N){ ^ In file included from /usr/include/math.h:83:0, from /opt/lang/gcc/include/c++/6.2.0/cmath:45, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:41, from func.cpp:2: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:153:16: note: candidate: double pow(double, double) __MATHCALL_VEC (pow,, (_Mdouble_ __x, _Mdouble_ __y)); ^~~ /usr/include/x86_64-linux-gnu/bits/mathcalls.h:153:16: note: candidate expects 2 arguments, 1 provided In file included from /opt/lang/gcc/include/c++/6.2.0/valarray:587:0, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:95, from func.cpp:2: /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:563:92: note: candidate: template<class _Tp> std::_Expr<std::_BinClos<std::_Pow, std::_Constant, std::_ValArray, _Tp, _Tp>, _Tp> std::pow(const _Tp&, const std::valarray<_Tp>&) /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:563:92: note: template argument deduction/substitution failed: func.cpp:21:17: note: candidate expects 2 arguments, 1 provided if(pow(sqrtN) == N){ ^ In file included from /opt/lang/gcc/include/c++/6.2.0/valarray:587:0, from /opt/lang/gcc/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:95, from func.cpp:2: /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:561:95: note: candidate: template<class _Tp> std::_Expr<std::_BinClos<std::_Pow, std::_ValArray, std::_Constant, _Tp, _Tp>, _Tp> std::pow(const std::valarray<_Tp>&, const _Tp&) /opt/lang/gcc/include/c++/6.2.0/bits/valarray_after.h:561:95: note: template argument deduction/substitution failed: func.cpp:21:17: note: mismatched types 'const std::valarray<_Tp>' and 'int' if(pow(sqrtN) == N){ ^ In file included from /opt/lang/gcc/include/c++/
Code: 14:04:27 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Code: 14:04:37 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i*i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Code: 14:04:48 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
if(N==1){
return 1;
}
for(int i=1; i*i<N; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Code: 14:05:40 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN) == N){
count++;
}
return count;
}
Code: 14:07:12 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(, 2) == N){
count++;
}
return count;
}
Code: 14:07:20 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 6 expected 8
Code: 14:07:59 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Code: 14:08:12 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 6 expected 8
stdout:
1 2 3
Code: 14:08:35 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<=sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Code: 14:08:37 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<=sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
Code: 14:09:15 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<=sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(()sqrtN , 2) == N){
count++;
}
return count;
}
Code: 14:09:26 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = (int) sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<=sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow((int)sqrtN , 2) == N){
count++;
}
return count;
}
Code: 14:10:08 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<=sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow((int)sqrtN , 2) == N){
count++;
}
return count;
}
Code: 14:10:16 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<=sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
Code: 14:10:26 UTC,
cpp,
autosave
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Code: 14:10:33 UTC,
cpp,
verify,
result: Failed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
int sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
expand all
Example tests
1.
0.001 s
WRONG ANSWER,
got 6 expected 8
stdout:
1 2 3
Code: 14:10:47 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
float sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
Code: 14:10:54 UTC,
cpp,
verify,
result: Passed
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
float sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis
Code: 14:11:01 UTC,
cpp,
final,
score: 
100
// you can use includes, for example:
#include <bits/stdc++.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int N) {
// write your code in C++14 (g++ 6.2.0)
int count = 0;
float sqrtN = sqrt(N);
if(N==1){
return 1;
}
for(int i=1; i<sqrtN; i++){
if( N%i == 0){
cout << i << endl;
count += 2;
}
}
if(pow(sqrtN , 2) == N){
count++;
}
return count;
}
Analysis summary
The solution obtained perfect score.
Analysis
Detected time complexity:
O(sqrt(N))
expand all
Correctness tests
1.
0.001 s
OK
stdout:
1 2
2.
0.001 s
OK
stdout:
1 2 3 4
1.
0.001 s
OK
2.
0.001 s
OK
stdout:
1
3.
0.001 s
OK
stdout:
1
4.
0.001 s
OK
stdout:
1
5.
0.001 s
OK
stdout:
1
6.
0.001 s
OK
stdout:
1 2
7.
0.001 s
OK
stdout:
1
8.
0.001 s
OK
stdout:
1 2
9.
0.001 s
OK
stdout:
1
10.
0.001 s
OK
stdout:
1 2
1.
0.001 s
OK
stdout:
1
2.
0.001 s
OK
stdout:
1 2 3 6
1.
0.001 s
OK
stdout:
1 3
2.
0.001 s
OK
stdout:
1 2 4
3.
0.001 s
OK
stdout:
1 2 3 4 5 6 8 10
1.
0.001 s
OK
stdout:
1 2 3 4 5 6 8 9 10 12 15 16 18 20 24
2.
0.001 s
OK
stdout:
1 11
1.
0.001 s
OK
stdout:
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 28 30 35 36 40 42 45 48 56 60 63 70
2.
0.001 s
OK
stdout:
1 3 5 15
1.
0.001 s
OK
stdout:
1 13
2.
0.001 s
OK
stdout:
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 28 30 32 35 36 40 42 45 48 56 60 63 64 70 72 80 84 90 96 105 112 120 126 128 140 144 160 168 180 192
1.
0.001 s
OK
expand all
Performance tests
1.
0.001 s
OK
stdout:
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 27 28 30 32 35 36 40 42 45 48 54 56 60 63 64 70 72 80 81 84 90 96 105 108 112 120 126 128 135 140 144 160 162 168 180 189 192 210 216 224 240 252 270 280 288 315 320 324 336 360 378 384 405 420 432 448 480 504 540 560 567 576
2.
0.001 s
OK
stdout:
1 2 13 26 31 62 403 806
1.
0.001 s
OK
stdout:
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 50 54 56 60 63 64 70 72 75 80 81 84 90 96 100 105 108 112 120 126 128 135 140 144 150 160 162 168 175 180 189 192 200 210 216 224 225 240 252 256 270 280 288 300 315 320 324 336 350 360 378 384 400 405 420 432 448 450 480 504 525 540 560 567 576 600 630 640 648 672 675 700 720 756 768 800 810 840 864 896 900 945 960 1008 1050 1080 1120 1134 1152 1200 1260 1280 1296 1344 1350 1400 1440 1512 1575 1600 1620 1680 1728 1792 1800 1890
2.
0.001 s
OK
stdout:
1 2 3 4 6 12
3.
0.001 s
OK
stdout:
1 2 4 8 13 16 26 43 52 86 104 169 172 208 338 344 559 676 688 1118 1352 1849
1.
0.001 s
OK
stdout:
1 359
2.
0.001 s
OK
stdout:
1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 18 20 21 22 24 25 27 28 30 32 33 35 36 40 42 44 45 48 50 54 55 56 60 63 64 66 70 72 75 77 80 81 84 88 90 96 99 100 105 108 110 112 120 126 128 132 135 140 144 150 154 160 162 165 168 175 176 180 189 192 198 200 210 216 220 224 225 231 240 252 256 264 270 275 280 288 297 300 308 315 320 324 330 336 350 352 360 378 384 385 396 400 405 420 432 440 448 450 462 480 495 504 525 528 540 550 560 567 576 594 600 616 630 640 648 660 672 675 693 700 704 720 756 768 770 792 800 810 825 840 864 880 891 896 900 924 945 960 990 1008 1050 1056 1080 1100 1120 1134 1152 1155 1188 1200 1232 1260 1280 1296 1320 1344 1350 1386 1400 1408 1440 1485 1512 1540 1575 1584 1600 1620 1650 1680 1728 1760 1782 1792 1800 1848 1890 1920 1925 1980 2016 2025 2079 2100 2112 2160 2200 2240 2268 2304 2310 2376 2400 2464 2475 2520 2592 2640 2688 2700 2772 2800 2816 2835 2880 2970 3024 3080 3150 3168 3200 3240 3300 3360 3456 3465 3520 3564 3600 3696 3780 3840 3850 3960 4032 4050 4158 4200 4224 4320 4400 4455 4480 4536 4620 4725 4752 4800 4928 4950 5040 5184 5280 5376 5400 5544 5600 5670 5760 5775 5940 6048 6160 6237 6300
3.
0.001 s
OK
stdout:
1 2 3 4 6 8 9 12 16 17 18 24 31 34 36 48 51 62 68 72 93 102 124 136 144 153 186 204 248 272 279 289 306 372 408 496 527 558 578 612 744 816 867 961 1054 1116 1156 1224 1488 1581 1734 1922 2108 2232 2312 2448 2601 2883 3162 3468 3844 4216 4464 4624 4743 5202 5766
1.
0.001 s
OK
stdout:
1 2 3 4 6 12 23 46 61 69 73 79 92 122 138 146 158 183 219 237 244 276 292 316 366 438 474 732 876 948 1403 1679 1817 2806 3358 3634 4209 4453 4819 5037 5451 5612 5767 6716 7268 8418 8906 9638
2.
0.001 s
OK
stdout:
1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192
1.
0.001 s
OK
stdout:
1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 18 20 21 22 24 25 27 28 30 32 33 35 36 40 42 44 45 48 50 54 55 56 60 63 64 66 70 72 75 77 80 81 84 88 90 96 99 100 105 108 110 112 120 126 128 132 135 140 144 150 154 160 162 165 168 175 176 180 189 192 198 200 210 216 220 224 225 231 240 243 252 256 264 270 275 280 288 297 300 308 315 320 324 330 336 350 352 360 378 384 385 396 400 405 420 432 440 448 450 462 480 486 495 504 512 525 528 540 550 560 567 576 594 600 616 630 640 648 660 672 675 693 700 704 720 756 768 770 792 800 810 825 840 864 880 891 896 900 924 945 960 972 990 1008 1024 1050 1056 1080 1100 1120 1134 1152 1155 1188 1200 1215 1232 1260 1280 1296 1320 1344 1350 1386 1400 1408 1440 1485 1512 1536 1540 1575 1584 1600 1620 1650 1680 1701 1728 1760 1782 1792 1800 1848 1890 1920 1925 1944 1980 2016 2025 2079 2100 2112 2160 2200 2240 2268 2304 2310 2376 2400 2430 2464 2475 2520 2560 2592 2640 2673 2688 2700 2772 2800 2816 2835 2880 2970 3024 3072 3080 3150 3168 3200 3240 3300 3360 3402 3456 3465 3520 3564 3584 3600 3696 3780 3840 3850 3888 3960 4032 4050 4158 4200 4224 4320 4400 4455 4480 4536 4608 4620 4725 4752 4800 4860 4928 4950 5040 5120 5184 5280 5346 5376 5400 5544 5600 5632 5670 5760 5775 5940 6048 6075 6160 6237 6300 6336 6400 6480 6600 6720 6804 6912 6930 7040 7128 7168 7200 7392 7425 7560 7680 7700 7776 7920 8064 8100 8316 8400 8448 8505 8640 8800 8910 8960 9072 9216 9240 9450 9504 9600 9720 9856 9900 10080 10368 10395 10560 10692 10752 10800 11088 11200 11264 11340 11520 11550 11880 12096 12150 12320 12474 12600 12672 12800 12960 13200 13365 13440 13608 13824 13860 14080 14175 14256 14400 14784 14850 15120 15360 15400 15552 15840 16128 16200 16632 16800 16896 17010 17280 17325 17600 17820 17920 18144 18480 18711 18900 19008 19200 19440 19712 19800 20160 20736 20790 21120 21384 21504 21600
2.
0.001 s
OK
stdout:
1
3.
0.001 s
OK
stdout:
1 3 9 27 81 2357 7071
1.
0.001 s
OK
stdout:
1 2 4 5 8 10 16 20 25 32 40 50 64 80 100 125 128 160 200 250 256 320 400 500 512 625 640 800 1000 1250 1280 1600 2000 2500 2560 3125 3200 4000 5000 6250 6400 8000 10000 12500 12800 15625 16000 20000 25000 31250
2.
0.001 s
OK
stdout:
1
3.
0.001 s
OK
stdout:
1 2 4 5 7 8 10 14 16 20 25 28 35 40 49 50 56 70 80 98 100 112 140 175 196 200 245 280 331 350 392 400 490 560 662 700 784 980 1225 1324 1400 1655 1960 2317 2450 2648 2800 3310 3920 4634 4900 5296 6620 8275 9268 9800 11585 13240 16219 16550 18536 19600 23170 26480 32438 33100 37072