Submission #32268032
Source Code Expand
#include <bits/stdc++.h>
template<typename T>
inline T chkmin(T& x, const T& y){if (x > y) x = y; return x;}
template<typename T>
inline T chkmax(T& x, const T& y){if (x < y) x = y; return x;}
using namespace std;
typedef long long ll;
const int NN = 1919810, N = 1e6;
int n, L, notprime[NN], phi[NN];
vector<int> plist;
inline void linear_sieve(int n)
{
notprime[1] = true; phi[1] = 1;
for (int i=2; i<=n; i++)
{
if (!notprime[i]){plist.emplace_back(i); phi[i] = i-1;}
for (auto x : plist)
{
int now = i*x;
if (now > n) break;
notprime[now] = true;
if (!(i%x)){phi[now] = phi[i] * x; break;}
phi[now] = phi[i] * phi[x];
}
}
}
ll F(int l, int n)
{
ll ans = 0;
for (int i=l; i*i<=n; i++) ans += phi[i] * (n / (i * i));
return ans;
}
int main()
{
scanf("%d", &n); L = sqrt(n); linear_sieve(L+1);
printf("%lld\n", F(1, n) + F(2, n));
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Together Square |
| User | Jijidawang |
| Language | C++ (GCC 9.2.1) |
| Score | 400 |
| Code Size | 985 Byte |
| Status | AC |
| Exec Time | 7 ms |
| Memory | 3780 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:35:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
35 | scanf("%d", &n); L = sqrt(n); linear_sieve(L+1);
| ~~~~~^~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 7 ms | 3728 KiB |
| example_01.txt | AC | 2 ms | 3692 KiB |
| test_00.txt | AC | 2 ms | 3724 KiB |
| test_01.txt | AC | 2 ms | 3632 KiB |
| test_02.txt | AC | 2 ms | 3700 KiB |
| test_03.txt | AC | 2 ms | 3676 KiB |
| test_04.txt | AC | 3 ms | 3632 KiB |
| test_05.txt | AC | 2 ms | 3628 KiB |
| test_06.txt | AC | 2 ms | 3780 KiB |
| test_07.txt | AC | 2 ms | 3776 KiB |
| test_08.txt | AC | 2 ms | 3736 KiB |
| test_09.txt | AC | 3 ms | 3676 KiB |
| test_10.txt | AC | 2 ms | 3628 KiB |
| test_11.txt | AC | 3 ms | 3764 KiB |