Linkin_Park

Codeforces contest "ICTIS ... october 2016 #1" - task C

Dec 10th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. /*
  2. Let's consider a table consisting of n rows and n columns.
  3. The cell located at the intersection of i-th row and j-th column contains number i × j.
  4. The rows and columns are numbered starting from 1.
  5.  
  6. You are given a positive integer x.
  7. Your task is to count the number of cells in a table that contain number x.
  8.  
  9. Input:
  10. The single line contains numbers n and x (1 ≤ n ≤ 10^5, 1 ≤ x ≤ 10^9) —
  11. the size of the table and the number that we are looking for in the table.
  12.  
  13. Output:
  14. Print a single number: the number of times x occurs in the table.
  15.  
  16. Examples:
  17.  
  18. input
  19. 10 5
  20. output
  21. 2
  22.  
  23. input
  24. 6 12
  25. output
  26. 4
  27.  
  28. input
  29. 5 13
  30. output
  31. 0
  32.  
  33. */
  34.  
  35. #include <iostream>
  36. #include <cstdio>
  37. #include <vector>
  38. #include <set>
  39. #include <map>
  40. #include <algorithm>
  41. #include <iterator>
  42. #include <string>
  43. #include <math.h>
  44.  
  45. using namespace std;
  46.  
  47. typedef long long int64;
  48.  
  49. int main()
  50. {
  51.     //freopen("input.txt", "r", stdin);
  52.     int64 n, x, qty = 0;
  53.     cin >> n >> x; // n - table size, x - the seeking number
  54.  
  55.     for (int i = 1; i <= n; i++) // checking all lines in the table
  56.     {
  57.         if (x % i == 0 && x / i <= n) // if there exists a number j that i * j = x and this j <= n (is on the table) then we increase qty
  58.         {
  59.             qty++;
  60.         }
  61.     }
  62.  
  63.     cout << qty << endl;
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment