Advertisement
kadeyrov

Untitled

Oct 17th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  AndeyLess
  4. //
  5. //  Created by Kadir Kadyrov on 08.07.2020.
  6. //  Copyright © 2020 Kadir Kadyrov. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <string>
  14.  
  15. #define INF 1000000000
  16. #define MAXE 1000000
  17. #define MAXV 1000
  18.  
  19. using namespace std;
  20.  
  21. int ex23(int n) {
  22.     int ans = 0;
  23.     for(int i = 1; i <= n; i++) {
  24.         if(n % i == 0) {
  25.             ans++;
  26.         }
  27.     }
  28.     return ans;
  29. }
  30.  
  31. int ex23_1(int n) {
  32.     int ans = 0;
  33.    
  34.     for (int i = 1; i <= sqrt(n); i++) { // div = 2 -> n/2
  35.         if(n % i == 0) {
  36.             ans += 2;
  37.         }
  38.     }
  39.     if (sqrt(n) * sqrt(n) == n) { // when n = x * x -> ans - 1
  40.         ans--;
  41.     }
  42.    
  43.     return ans;
  44. }
  45.  
  46. int sumOfDig1(int n) {
  47.     int ans = 0;
  48.     while(n > 0) { // 102 -> 10
  49.         ans += n % 10;
  50.         n /= 10;
  51.     }
  52.     return ans;
  53. }
  54. int sumOfDig2(int n) {
  55.     string s = to_string(n);
  56.    
  57.     int ans = 0;
  58.     for (int i = 0; i < s.size(); i++) {
  59.         ans += (s[i] - '0'); // '0' - 42 '1' - 43, '0' - 42 - '0' = 0, '1' - '0' = 1
  60.     }
  61.     return ans;
  62. }
  63. int sumOfDig3(int n) {
  64.     int ans = (n % 10) + ((n / 10) % 10) + (n / 100);
  65.     return ans;
  66. }
  67.  
  68. /// n%7 sum(n) %7
  69. void ex25() {
  70.     for (int x = 100; x <= 999; x++) {
  71.         if (x % 7 == 0 && sumOfDig1(x) % 7 == 0)
  72.             cout << x << endl;
  73.     }
  74. }
  75.  
  76. int main() {
  77.     ex25();
  78.     //cout << ex23(10) << ' ' << ex23_1(10) << ' ' << ex23_1(25) << endl;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement