Click here to Skip to main content
13,738,608 members

C / C++ / MFC

 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
Richard MacCutchan27-Mar-18 22:08
protectorRichard MacCutchan27-Mar-18 22:08 
AnswerRe: error C2143: syntax error: missing ':' before 'constant' Pin
Jochen Arndt27-Mar-18 22:41
mvpJochen Arndt27-Mar-18 22:41 
GeneralRe: error C2143: syntax error: missing ':' before 'constant' The Hercules makefile has V1,V2,V3,V4 Pin
ForNow28-Mar-18 15:44
memberForNow28-Mar-18 15:44 
Questionproblem understanding a functionality of constructor. Pin
Tarun Jha27-Mar-18 4:39
memberTarun Jha27-Mar-18 4:39 
AnswerRe: problem understanding a functionality of constructor. Pin
Jochen Arndt27-Mar-18 4:55
mvpJochen Arndt27-Mar-18 4:55 
AnswerRe: problem understanding a functionality of constructor. Pin
Richard MacCutchan27-Mar-18 5:18
protectorRichard MacCutchan27-Mar-18 5:18 
AnswerRe: problem understanding a functionality of constructor. Pin
CPallini27-Mar-18 5:36
mvpCPallini27-Mar-18 5:36 
QuestionHackerrank:Down to Zero problem Pin
SrinivasaRamanujan25-Mar-18 10:23
memberSrinivasaRamanujan25-Mar-18 10:23 
Problem statement: You are given Q queries. Each query consists of a single number N. You can perform any of the 2 operations on in each move:

1: If we take 2 integers a and b where N=aXb(a!=1,b!=1) then we can change N=max(a,b).

2: Decrease the value of N by 1. Determine the minimum number of moves required to reduce the value of N to 0

Input Format

The first line contains the integer Q.

The next Q lines each contain an integer,N .

Output Format

Output Q lines. Each line containing the minimum number of moves required to reduce the value of N to 0.

Sample Input

2

3

4

Sample Output

3

3

Explanation

For test case 1, We only have one option that gives the minimum number of moves. Follow 3->2 -> 1->0 .

Hence, 3 moves.

For the case 2, we can either go 4->3 ->2 ->1 ->0 or4 -> 2-> 1->0 . The 2nd option is more optimal. Hence, 3 moves.

My algo:

if a number is N then

I do looping until sqrt(N) to find if it is a prime or not.
if it is a prime number then N=N-1
if it not a prime number,one of the largest factor(say a) is <=sqrt(N) then other will be b=N/a now b>a then put N=b;
increment count(pass by value).
then next iteration for N ,until it is greater than 1.
return count.

algorithms works fine with small value but predicts less optimal solution for large values.why?
AnswerRe: Hackerrank:Down to Zero problem Pin
David Crow25-Mar-18 15:41
memberDavid Crow25-Mar-18 15:41 
QuestionIn type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 5:14
memberTarun Jha25-Mar-18 5:14 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
Victor Nijegorodov25-Mar-18 8:07
memberVictor Nijegorodov25-Mar-18 8:07 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 23:26
memberTarun Jha25-Mar-18 23:26 
AnswerRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini25-Mar-18 10:50
mvpCPallini25-Mar-18 10:50 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
Tarun Jha25-Mar-18 23:25
memberTarun Jha25-Mar-18 23:25 
GeneralRe: In type conversion of 2 different classes can i convert both ways ? Pin
CPallini26-Mar-18 0:18
mvpCPallini26-Mar-18 0:18 
QuestionAdding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 8:19
memberTarun Jha24-Mar-18 8:19 
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Victor Nijegorodov24-Mar-18 8:35
memberVictor Nijegorodov24-Mar-18 8:35 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha24-Mar-18 10:06
memberTarun Jha24-Mar-18 10:06 
AnswerRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan24-Mar-18 21:13
protectorRichard MacCutchan24-Mar-18 21:13 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 5:08
memberTarun Jha25-Mar-18 5:08 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan25-Mar-18 5:32
protectorRichard MacCutchan25-Mar-18 5:32 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 6:37
memberTarun Jha25-Mar-18 6:37 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Richard MacCutchan25-Mar-18 7:16
protectorRichard MacCutchan25-Mar-18 7:16 
GeneralRe: Adding two matrix objects and assigning the result to third object using overloaded operators ? Pin
Tarun Jha25-Mar-18 8:06
memberTarun Jha25-Mar-18 8:06 
QuestionLinux C++ implementation of ioctl SOLVED Pin
Vaclav_23-Mar-18 8:50
memberVaclav_23-Mar-18 8:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 21 Oct 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid