File: primeNumber.cpp

package info (click to toggle)
stopt 5.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,860 kB
  • sloc: cpp: 70,456; python: 5,950; makefile: 72; sh: 57
file content (37 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2016 EDF
// All Rights Reserved
// This code is published under the GNU Lesser General Public License (GNU LGPL)
#include <vector>

namespace StOpt
{

std::vector<int> primeNumber(int  n)
{
    std::vector<int> ret ;

    int d = 2;

    if (n < 2)
        return ret;

    while (d < n)
    {
        /* if valid prime factor */
        if (n % d == 0)
        {
            ret.push_back(d);
            n /= d;
        }
        /* else: invalid prime factor */
        else
        {
            if (d == 2) d = 3;
            else d += 2;
        }
    }
    ret.push_back(d);

    return ret ;
}
}