Submission #477809

#TimeUsernameProblemLanguageResultExecution timeMemory
477809sumit_kk10Modsum (NOI12_modsum)C++14
25 / 25
142 ms464 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int MOD = 5; const int N = 1e7 + 5; int n, v[N], w[N]; vector<int> vv; long long ans; ll power(ll x, ll y){ x %= MOD; ll ans = 1; while(y){ if(y & 1) ans = (ans * x) % MOD; y >>= 1LL; x = (x * x) % MOD; } return ans; } int calc(){ long long int sum = 0; for(auto k : vv) sum += k; long long ok = power(sum, 4); ok = (ok % 5); ok += 2 * (power(sum, 2)); ok = (ok % 5); return (ok + 1); } void go(int i){ if(i == n + 1){ ans += calc(); return; } for(int j = v[i]; j <= w[i]; ++j){ vv.push_back(j); go(i + 1); vv.pop_back(); } } void solve(){ cin >> n; for(int i = 1; i <= n; ++i) cin >> v[i] >> w[i]; go(1); cout << ans << '\n'; } int main() { fast; int t = 1; // cin >> t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...