ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 1834번: 나머지와 몫이 같은 수
    정수론(Number theory) 2018. 7. 15. 16:17
    반응형

    https://www.acmicpc.net/problem/1834


    1. 문제

    N으로 나누었을 때 나머지와 몫이 같은 모든 자연수의 합을 구하는 프로그램을 작성하시오. 예를 들어 N=3일 때, 나머지와 몫이 모두 같은 자연수는 4와 8 두 개가 있으므로, 그 합은 12이다.


    2. 알고리즘

    키워드 - 수학

    접근법


    모든 수를 개산할 필요 없이 규칙을 찾아야 한다.


    N = 2일 때, [3]

    N = 3일 때, [4, 8]

    N = 4일 때, [5, 10, 15]

    N = 5일 때, [6, 12, 18, 24]


    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
    38
    39
    40
    41
    #include <iostream>
    #include <sstream>
    #include <string>
    #include <algorithm>
    #include <functional>
    #include <vector>
    #include <list>
    #include <queue>
    #include <deque>
    #include <map>
    #include <set>
    #include <stack>
    #include <cstring>
     
    using namespace std;
     
    #define MAX_SIZE 100
    #define INF 0x7fffffff
    #define CENDL "\n"
    #define ll long long
     
    int main() {
     
        cin.tie(0);
        std::ios::sync_with_stdio(false);
        
        int n; cin >> n;
     
        ll sol = 0;
        // n = 0,
        // n = 2, 3
        // n = 3, [4, 8]
        // n = 4, [5, 10, 15]    
        for(long i=1; i<n; i++) {
            sol += (n+1* i;
        }
     
        cout << sol << CENDL;
        return 0;
    }
     
    cs

    반응형

    '정수론(Number theory)' 카테고리의 다른 글

    백준 2153번: 소수 단어  (0) 2018.07.16
    백준 4880번: 다음수  (0) 2018.07.15
    백준 2355번: 시그마  (0) 2018.07.15
    백준 10610번: 30  (0) 2018.07.10
    백준 10757번: 큰 수 A+B  (0) 2018.07.03

    댓글

Designed by Tistory.