Toph Number theory Problem Left Prime Solution

Solve in C++:
///**********ALLAH IS ALMIGHTY************/// ///AH Tonmoy ///Department of CSE ///Islamic University,Bangladesh #include<iostream> #include<math.h> const int n=10000000; bool marked[n+1]; int c[n+1]; using namespace std; void sieve() { marked[0] = marked[1] = true; for(int i=4; i<=n; i+=2) { marked[i] = true; } int sq=sqrt(n); for (int i = 3; i<=sq;i += 2) { for(int j=i*i; j<=n; j += i+i) { marked[j]=true; } } } void result() { int cnt = 0; for (int i = 0; i <= n; i++) { c[i] = cnt; if (!marked[i]) cnt++; } } int main() { sieve(); result(); int t, a; cin>>t; while (t--) { cin>>a; printf("%d\n", c[a]); } return 0; }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.