- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define S 5000003
- using namespace std;
- bool prime[S];
- __int64 primeD[S];
- void seive(){
- int last;
- for(int i = 2; i <= S; i++){
- if(prime[i]){
- primeD[i] = i-1;
- for(int j = i+i; j <= S; j+=i){
- prime[j] = false;
- if(!primeD[j])primeD[j] = (__int64)j - (j/i);
- else primeD[j] -= (primeD[j]/i);
- }
- }
- }
- for(int i = 2; i <= S; i++)primeD[i] *= primeD[i];
- }
- void cumulative_sum(){
- for(int i = 3; i <= S; i++){
- primeD[i] = primeD[i-1]+primeD[i];
- }
- }
- int main(){
- memset(prime, true, sizeof(prime));
- seive();
- cumulative_sum();
- int t, a, b, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &a, &b);
- printf("Case %d: %llu\n", ++cs, primeD[b]-primeD[a-1]);
- }
- return 0;
- }
Friday, February 26, 2016
LightOJ - 1007 - Mathematically Hard
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment