답안 #1104739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104739 2024-10-24T09:51:52 Z dzhoz0 Savrsen (COCI17_savrsen) C++17
120 / 120
412 ms 39672 KB
/*
    ghmt the cutie :3
          UwU
*/

#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>

const int MOD = 1'000'000'000 + 7;

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    if (!name.empty())
    {
        freopen((name + ".INP").c_str(), "r", stdin);
        freopen((name + ".OUT").c_str(), "w", stdout);
    }
#endif
}

const int MAXN = 1e7;

int sieve[MAXN + 5];

void init() {
    memset(sieve, 0, sizeof(sieve));
    for(long long i = 2; i <= MAXN; i++) {
        if(sieve[i] != 0) continue;
        sieve[i] = i;
        for(long long j = i * i; j <= MAXN; j += i) {
            sieve[j] = (sieve[j] == 0 ? i : sieve[j]);
        }
    }
}
long long f(int n) {
    long long res = 1;
    
    while(n > 1) {
        int d = sieve[n];
        int e = 1;
        while(n % d == 0) e++, n /= d;
        long long sum = 0, pw = 1;
        while(e--) {
            sum += pw;
            pw *= d;
        }
        res *= sum;
    }
    return res;
}

void solve()
{
    init();
    // for(int i = 1; i <= 20; i++) cout << i << ' ' << sieve[i] << '\n';
    int l, r; cin >> l >> r;
    // cout << f(4) << '\n';
    long long res = 0;
    for(int x = l; x <= r; x++) {

        res += abs(x - (f(x) - x));
    }

    cout << res << '\n';
}
signed main()
{
    setIO();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

Compilation message

savrsen.cpp: In function 'void setIO(std::string)':
savrsen.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
savrsen.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name + ".OUT").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 39504 KB Output is correct
2 Correct 51 ms 39504 KB Output is correct
3 Correct 56 ms 39672 KB Output is correct
4 Correct 52 ms 39504 KB Output is correct
5 Correct 375 ms 39504 KB Output is correct
6 Correct 412 ms 39504 KB Output is correct
7 Correct 391 ms 39504 KB Output is correct
8 Correct 149 ms 39504 KB Output is correct