fork download
  1. #include <bits/stdc++.h>
  2. #define MAXN 10000010
  3. #define STIZE(x) printf("STIZE%d\n", x)
  4. using namespace std;
  5. int mindel[MAXN], a, b;
  6. long long rez;
  7. void sieve(int B) {
  8. for (int i = 2; i <= B; i++) {
  9. if (!mindel[i]) {
  10. mindel[i] = i;
  11. if (i<=sqrt(B)+1)
  12. for (int j=i*i;j<=B;j+=i)
  13. if(!mindel[j])
  14. mindel[j]= i;
  15. }
  16. }
  17. }
  18. long long zbir(int base, int stepen) {
  19. long long rez = 1;
  20. for(int i = 0; i < stepen; i++) {
  21. rez = base*rez + 1;
  22. }
  23. return rez;
  24. }
  25. long long zbirDelilaca(int n) {
  26. int poc = n;
  27. long long rez = 1;
  28. int curMinDel = mindel[n];
  29. int cnt = 0;
  30. while(n > 1) {
  31. if(curMinDel != mindel[n]) {
  32. rez *= zbir(curMinDel, cnt);
  33. curMinDel = mindel[n];
  34. cnt = 0;
  35. }
  36. n /= mindel[n];
  37. cnt++;
  38. }
  39. rez *= zbir(curMinDel, cnt);
  40. return rez - poc;
  41. }
  42.  
  43. int main() {
  44. scanf("%d%d", &a, &b);
  45. sieve(b);
  46. for(int i = a; i <= b; i++) {
  47. rez += abs(i - zbirDelilaca(i));
  48. }
  49. printf("%lld", rez);
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 41808KB
stdin
Standard input is empty
stdout
1