Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // SumOfDivisor
- //
- // Created by Rizky Herucakra on 7/5/13.
- // Copyright (c) 2013 Rizky Herucakra. All rights reserved.
- //
- #include <iostream>
- #include <vector>
- #include <numeric>
- using namespace std;
- vector<int> get_divisor_of(int val){
- vector<int> result;
- for (int i = 1; i <= val; ++i){
- if ( (val % i) == 0) result.push_back(i);
- }
- return result;
- }
- int sum_of(const vector<int>& v){
- return accumulate(v.begin(), v.end(),0);
- }
- int main(int argc, const char * argv[])
- {
- cout << "following number [1- 1000] is equal with it's sum of divisor :" << endl;
- for (int i = 1; i <= 100; ++i){
- int sumval = sum_of(get_divisor_of(i));
- cout << " i = " << i << " sum of divisor = " << sumval << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement