# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
467894 | kakayoshi | Savrsen (COCI17_savrsen) | C++14 | 1124 ms | 43692 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef pair<ll, pair<ll, ll> > pii;
#define forw(i,a,b) for (ll i=a;i<=b;i++)
#define forb(i,a,b) for (ll i=a;i>=b;i--)
#define fast {ios::sync_with_stdio(false); cin.tie(0); }
#define fi first
#define se second
#define pu push
#define puf push_front
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fr front
#define all(a) a.begin(),a.end()
const ll oo=1e18;
const ll mod=1e9;
const int base=31;
const int tx[4]={0,0,1,-1};
const int ty[4]={1,-1,0,1};
// custom
const ll maxN=1e7+2;
const int tx1[4]={2,2,1,-1};
const int ty1[4]={-1,1,2,2};
/////
ll a, b,ans;
vector <int> prime; //prime
vector <int> spf; // smallest prime factor
void sieve()
{
spf.assign(maxN+5,2);
spf[1]=1;
prime.pb(2);
for(int i=3;i<=maxN;i+=2)
{
if (spf[i]==2)
prime.pb(spf[i]=i);
for(int j=0;j<prime.size() && prime[j]*i<=maxN && prime[j]<=spf[i];j++)
spf[i*prime[j]]=prime[j];
}
}
ll power(ll a,ll n)
{
ll ans=1;
while (n>0)
{
if (n&1) ans=ans*a;
a=a*a;
n>>=1;
}
return ans;
}
ll get(int x)
{
ll ans=1;
while (x>1)
{
int p=spf[x];
int res=0;
while (x%p==0)
{
x/=p;
res++;
}
ans*=(power(p,res+1)-1)/(p-1);
}
return ans;
}
void solve()
{
sieve();
cin>>a>>b;
forw(i,a,b)
ans+=abs(2*i-get(i));
cout<<ans<<endl;
}
int main()
{
fast;
//freopen("HHH.inp","r",stdin);
//freopen("HHH.out","w",stdout);
ll t=1; //cin>>t;
while (t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |