diff --git a/ACPC10A.CPP b/ACPC10A.CPP new file mode 100644 index 0000000..f9fe5c5 --- /dev/null +++ b/ACPC10A.CPP @@ -0,0 +1,26 @@ +#include + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" + +int main() +{ + fast; + int a1,a2,a3; + while(cin >> a1 >> a2 >> a3) + { + if(a1==0 && a2==0 && a3==0) + break; + if(a2-a1==a3-a2) + { + cout << "AP " << 2*a3-a2 << endl; + } + else if(a2/a1==a3/a2) + { + cout << "GP " << a3*a3/a2 << endl; + } + } +} \ No newline at end of file diff --git a/ANARC05B.CPP b/ANARC05B.CPP new file mode 100644 index 0000000..f51b102 --- /dev/null +++ b/ANARC05B.CPP @@ -0,0 +1,59 @@ + #include + using namespace std; + #define ll long long int + #define pb push_back + #define PI 3.1415926535897932384626 + #define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) + #define MOD 1000000007 + #define forn(i,n) for(int i=0;i>n; + while(n) + { + int m,s1=1,s2=1,ans=0; + int arr[n]; + forn(i,n) + cin>>arr[i]; + cin>>m; + int brr[m]; + forn(i,m) + cin>>brr[i]; + + int pref[n+1]; + pref[0]=0; + pref[1]=arr[0]; + for(int i=2;i<=n;i++) + pref[i]=pref[i-1]+arr[i-1]; + + + int cref[m+1]; + cref[0]=0; + cref[1]=brr[0]; + + + for(int i=2;i<=m;i++) + cref[i]=cref[i-1]+brr[i-1]; + + for(int i=0;i>n; + } + + } \ No newline at end of file diff --git a/ANARC09B.cpp b/ANARC09B.cpp new file mode 100644 index 0000000..c940c09 --- /dev/null +++ b/ANARC09B.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" + +long long gcd(long long a, long long b) +{ + if(b==0) + return a; + else + return gcd(b,a%b); +} + +long long lcm(long long a, long long b) +{ + return a*b/gcd(a,b); +} + +int main() +{ +// fast; + long long w, h, x, a, b; + while(cin >> w >> h) + { + if(w==0 && h==0) + break; + else + { + x=lcm(w,h); + a=x/w; + b=x/h; + } + cout << a*b << endl; + } + +} \ No newline at end of file diff --git a/AP2.cpp b/AP2.cpp new file mode 100644 index 0000000..9fd516e --- /dev/null +++ b/AP2.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +using namespace std ; +#define endl "\n" +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long + +int main () +{ + int t, i; + cin >> t; + while(t--) + { + ll first_third,last_third,sum; + cin >> first_third >> last_third >> sum; + ll n= (sum*2)/(first_third+last_third); + cout << n << endl; + ll d=(last_third-first_third)/(n-5); +// cout << d << endl; + ll first_term=first_third-2*d; + ll x=first_term; + for(i=0;i +#include + + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" + +int main() +{ + fast; + int t,i; + cin >> t; + while(t--) + { + int ng, nm,max1=0,max2=0; + cin >> ng >> nm; + int arr1[ng], arr2[nm]; + for(i=0;i> arr1[i]; + max1=max(arr1[i],max1); + } + for(i=0;i> arr2[i]; + max2=max(arr2[i],max2); + } + if(max1>max2) + { + cout << "Godzilla" << endl; + } + else if(max1 + using namespace std; + #define ll long long + #define fast ios_base::sync_with_stdio(0);cin.tie(0); + #define endl "\n" + #define for0(i, n) for (int i = 0; i < n; i++) + #define for1(i, n) for (int i = 1; i < n; i++) + #define loop(i,a,b) for(int i=a;ib;i--) + #define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) + #define all(x) (x).begin(),(x).end() + #define allr(x) (x).rbegin(),(x).rend() + #define eb emplace_back + #define pb push_back + #define mp make_pair + #define fi first + #define se second + #define sll set + #define vll vector + #define msl map + #define mll map + ll i, j, k; + int main() + { + ll t; + cin >> t; + while(t--) + { + ll n; + cin >> n; + vll vec; + while(n--) + { + string s; + ll x; + + cin >> s; + cin >> x; + vec.push_back(x); + } + sort(all(vec)); + ll res = 0; + for (i = 0; i < vec.size();i++) + { + res += abs(vec[i] - (i+1)); + } + cout << res << endl; + vec.clear(); + + } + } \ No newline at end of file diff --git a/BALIFE.cpp b/BALIFE.cpp new file mode 100644 index 0000000..8efb47e --- /dev/null +++ b/BALIFE.cpp @@ -0,0 +1,57 @@ + /************ + Author :- Profesor(Abhishek) + 25.09.2020 11.23.42 + **********/ + #include + using namespace std; + #define ll long long + #define fast ios_base::sync_with_stdio(0);cin.tie(0); + #define endl "\n" + #define for0(i, n) for (int i = 0; i < n; i++) + #define for1(i, n) for (int i = 1; i < n; i++) + #define loop(i,a,b) for(int i=a;ib;i--) + #define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) + #define all(x) (x).begin(),(x).end() + #define allr(x) (x).rbegin(),(x).rend() + #define eb emplace_back + #define pb push_back + #define mp make_pair + #define fi first + #define se second + #define sll set + #define vll vector + #define msl map + #define mll map + ll i, j, k; + int main() + { + ll n; + while (cin >> n) + { + if (n == -1) return 0; + ll arr[n], sum = 0, max_diff = 0; + for0(i, n) + { + cin >> arr[i]; + sum += arr[i]; + } + if(sum % n != 0) + { + cout << "-1" << endl; + continue; + } + else + { + ll load = sum / n; + ll diff = 0; + for (ll i = 0; i < n; i++) + { + + diff += (arr[i] - load); + max_diff = max(max_diff, abs(diff)); + } + } + cout << max_diff << endl; + } + } \ No newline at end of file diff --git a/BUSYMAN.cpp b/BUSYMAN.cpp new file mode 100644 index 0000000..8a433ae --- /dev/null +++ b/BUSYMAN.cpp @@ -0,0 +1,75 @@ + /************ + Author :- Profesor(Abhishek) + 23.09.2020 17.45.06 + **********/ + #include + using namespace std; + #define ll long long + #define fast ios_base::sync_with_stdio(0);cin.tie(0); + #define endl "\n" + #define for0(i, n) for (int i = 0; i < n; i++) + #define for1(i, n) for (int i = 1; i < n; i++) + #define loop(i,a,b) for(int i=a;ib;i--) + #define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) + #define all(x) (x).begin(),(x).end() + #define allr(x) (x).rbegin(),(x).rend() + #define eb emplace_back + #define pb push_back + #define mp make_pair + #define fi first + #define se second + #define sll set + #define vll vector + #define msl map + #define mll map + ll i, j, k; + + bool cmp(const pair &a,const pair &b) + { + return (a.second < b.second); + } + + int main() + { + ll t=1; + cin >> t; + while(t--) + { + ll n; + cin >> n; + vector> vec; + ll start, finish; + for0(i, n) + { + cin >> start >> finish; + vec.push_back(mp(start, finish)); + } + sort(all(vec), cmp); + + // for (int i=0; i= fin) + { + cnt++; + fin = vec[i].se; + } + } + cout << cnt << endl; + } + + + // cout << endl << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; + return 0; + } \ No newline at end of file diff --git a/CANTON.cpp b/CANTON.cpp new file mode 100644 index 0000000..3c041a6 --- /dev/null +++ b/CANTON.cpp @@ -0,0 +1,63 @@ +#include +using namespace std; + +#define ll long long int +#define endl "\n" +#define fast ios_base::sync_with_stdio(false);cin.tie(NULL); +#define MOD 1000000007 +#define For(i,a,b) for(i=a;i 1 && k < n) { + i++, j--, k++; + } + + if (k == n) + break; + + i++, k++; + + if (k == n) + break; + + // loop for traversing from left + // to right upwards diagonally + while (i > 1 && k < n) { + i--, j++, k++; + } + } + cout << "TERM "<< n<<" IS "<< i << "/" <> t; + while(t--) + { + int n; + cin >>n; + georgeCantor(n); + } + +} \ No newline at end of file diff --git a/CEQU.cpp b/CEQU.cpp new file mode 100644 index 0000000..93e6560 --- /dev/null +++ b/CEQU.cpp @@ -0,0 +1,66 @@ +/************ + + Author :- Profesor(Abhishek) + 2020-09-01-13.17.13 +**********/ +#include + +using namespace std; + +#define ll long long +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define endl "\n" +#define fori(i,a,b) for(ll i=a;i=b;i--) +#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) +#define all(x) (x).begin(),(x).end() +#define allr(x) (x).rbegin(),(x).rend() +#define eb emplace_back +#define pb push_back +#define mp make_pair +#define fi first +#define se second +#define sll set +#define vll vector +#define msl map +#define mll map + +ll i, j, k; + +ll gcd(ll a, ll b) +{ + if(b==0) + return a; + return gcd(b,a%b); +} + +ll find_any_solution(ll a, ll b, ll c) +{ + if(!(c%gcd(a,b))) + { + return 1; + } + else + return 0; +} + +int main() +{ + ll t, x=0; + cin >> t; + while(t--) + { + x++; + ll a, b, c; + cin >> a >> b >> c; + cout<<"Case "< + using namespace std; + #define ll long long int + #define pb push_back + #define PI 3.1415926535897932384626 + #define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) + #define MOD 1000000007 + #define endl "\n" + +// string complement_string(string s) +// { +// int i; +// string complement=""; +// for(i=0;i> t; + while(t--) + { + int c=0; + long long n, k; + cin >> k >> n; + + if(n==1) + cout << "Male" << endl; + else if(n==2) + cout << "Female" << endl; + else{ + + n=n-1; + + while(n>1) + { + + if(n%2!=0) + { + c++; + n=n-1; + } + n=n/2; + + } + if(c%2==0) + cout << "Female" << endl; + else + cout << "Male" << endl; + + + + } + } + } \ No newline at end of file diff --git a/DEFKIN.cpp b/DEFKIN.cpp new file mode 100644 index 0000000..bb7d65c --- /dev/null +++ b/DEFKIN.cpp @@ -0,0 +1,64 @@ + /************ + Author :- Profesor(Abhishek) + 25.09.2020 15.42.18 + **********/ + #include + using namespace std; + #define ll long long + #define fast ios_base::sync_with_stdio(0);cin.tie(0); + #define endl "\n" + #define for0(i, n) for (int i = 0; i < n; i++) + #define for1(i, n) for (int i = 1; i < n; i++) + #define loop(i,a,b) for(int i=a;ib;i--) + #define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) + #define all(x) (x).begin(),(x).end() + #define allr(x) (x).rbegin(),(x).rend() + #define eb emplace_back + #define pb push_back + #define mp make_pair + #define fi first + #define se second + #define sll set + #define vll vector + #define msl map + #define mll map + ll i, j, k; + int main() + { + ll t=1; + cin >> t; + while(t--) + { + ll w, h, n; + cin >> w >> h >> n; + if(n == 0) + { + cout << w * h << endl; + continue; + } + ll width[n], height[n], max1=0 , max2 = 0; + for (i = 0; i < n;i++) + { + cin >> width[i] >> height[i]; + } + sort(width, width + n); + sort(height, height + n); + for (i = 1; i < n; i++) + { + max1 = max(max1, width[i] - width[i - 1] -1); + max2 = max(max2, height[i] - height[i - 1] -1); + // cout << max1 << " " << max2 << endl; + } + max1 = max(max1, width[0] -1 ); + max1 = max(max1, w - width[n-1]); + max2 = max(max2, height[0] - 1); + max2 = max(max2, h- height[n-1]); + + cout << max1 * max2 << endl; + } + + + // cout << endl << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; + return 0; + } \ No newline at end of file diff --git a/DOTAA.cpp b/DOTAA.cpp new file mode 100644 index 0000000..38988e6 --- /dev/null +++ b/DOTAA.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; +#define ll long long int +#define endl "\n" +#define fast ios_base::sync_with_stdio(false);cin.tie(NULL); + +ll i,j; + +int main() +{ + fast; + int t; + cin >> t; + while(t--) + { + int no_of_heroes, no_of_towers, damage,sum=0; + cin >> no_of_heroes >> no_of_towers >> damage; + int health[no_of_heroes]; + for(i=0;i> health[i]; + if(health[i]>damage) + { + if(health[i]%damage==0) + { + sum=sum+(health[i]/damage-1); + } + else + { + sum=sum+health[i]/damage; + } + } + } + if(sum >= no_of_towers) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} \ No newline at end of file diff --git a/EASYPROB.TXT b/EASYPROB.TXT new file mode 100644 index 0000000..6d5d519 --- /dev/null +++ b/EASYPROB.TXT @@ -0,0 +1,5 @@ +137=2(2(2)+2+2(0))+2(2+2(0))+2(0) 1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0) +73=2(2(2)+2)+2(2+2(0))+2(0) 136=2(2(2)+2+2(0))+2(2+2(0)) +255=2(2(2)+2+2(0))+2(2(2)+2)+2(2(2)+2(0))+2(2(2))+2(2+2(0))+2(2)+2+2(0) +1384=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2)+2(2(2)+2(0))+2(2+2(0)) +16385=2(2(2+2(0))+2(2)+2)+2(0) \ No newline at end of file diff --git a/EGYPIZZA.cpp b/EGYPIZZA.cpp new file mode 100644 index 0000000..d90da24 --- /dev/null +++ b/EGYPIZZA.cpp @@ -0,0 +1,35 @@ + #include + #include + #include + #include + using namespace std; + + int main() { + int n; + int half=0,one4=0,three4=0; + scanf("%d",&n);//no. of slices + char st[5]; + while(n--) + { + scanf(" %s",st); + if(strcmp(st,"1/4")==0) one4++; + if(strcmp(st,"1/2")==0) half++; + if(strcmp(st,"3/4")==0) three4++;//counting no.of slices of each type + } + int sum=three4;//counting no.of 3/4 slices + three4-=one4;//fitting them with 1/4 slices + if(three4<0)//if its negative, means there still some 1/4 slices + { + double k=(-three4 * 1.0/4.0);//sum all left over 1/4 slices + sum=sum+(int)k;//add no.of pizzas + k=k-(int)k;//amount cut off last pizza,its <1 + k=1-k;//amount left in last pizza + if(k>=0.5 && half>0)//if amount left is still >=0.5 + half--;//cut off a half from it + sum++;//add no. of pizza + } + sum=sum+(ceil(half*0.5));//add rest of half slices + sum=sum+1;//add one pizza of winner + printf("%d\n",sum); + return 0; + } \ No newline at end of file diff --git a/EIGHTS.cpp b/EIGHTS.cpp new file mode 100644 index 0000000..8b6f33a --- /dev/null +++ b/EIGHTS.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" + +int main() +{ + fast; + ll t; + cin >> t; + while(t--) + { + ll n; + cin >> n; + cout << 192+((n-1)*250) << endl; + } +} \ No newline at end of file diff --git a/ENIGMATH.cpp b/ENIGMATH.cpp new file mode 100644 index 0000000..cafae2d --- /dev/null +++ b/ENIGMATH.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +#define ll long long int +#define endl "\n" +#define fast ios_base::sync_with_stdio(false);cin.tie(NULL); +#define MOD 1000000007 +#define For(i,a,b) for(i=a;i> t; + while(t--) + { + ll a, b, x, y; + cin >> a >> b; + ll divby=gcd(a,b); + x=b/divby; + y=a/divby; + cout << x << " " << y << endl; + + } + +} \ No newline at end of file diff --git a/FACEFRND.cpp b/FACEFRND.cpp new file mode 100644 index 0000000..968be48 --- /dev/null +++ b/FACEFRND.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" +#define TEST int t;cin >> t;while(t--) + +int main() +{ + setfof; + int t; + cin >> t; + int y=t; + while(t--) + { + int fbfriend, n; + cin >> fbfriend >> n; + fof.insert(fbfriend); + int x; + for(int i=0;i> x; + fof.insert(x); + } + } +// set::iterator it; +// for(it=fof.begin();it!=fof.end();it++) +// cout << *it << " "; + cout << fof.size()-y << endl; +} \ No newline at end of file diff --git a/FCTRL.cpp b/FCTRL.cpp new file mode 100644 index 0000000..b72cf31 --- /dev/null +++ b/FCTRL.cpp @@ -0,0 +1,22 @@ +#include +#include + +using namespace std; + +int main() +{ + int t; + cin >> t; + while(t--) + { + int n,ans=0, i=1; + cin >> n; + while(pow(5,i)<=n) + { + int x=n/pow(5,i); + ans=ans+x; + i++; + } + cout << ans << endl; + } +} \ No newline at end of file diff --git a/GIRLSNBS.cpp b/GIRLSNBS.cpp new file mode 100644 index 0000000..b17c154 --- /dev/null +++ b/GIRLSNBS.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +int main() +{ + int g, b; + double x, y, z, ans; + while(cin >> g >> b) + { + if(g==-1 && b==-1) + break; + if(g==0||b==0) + cout << max(g,b) << endl; + else + { + x=min(g,b); + x=x+1; + y=max(g,b); + ans=y/x; + cout << ceil(ans) << endl; + } + } + +} \ No newline at end of file diff --git a/HOTELS.CPP b/HOTELS.CPP new file mode 100644 index 0000000..19631c8 --- /dev/null +++ b/HOTELS.CPP @@ -0,0 +1,38 @@ + #include + + using namespace std; + + #define fast ios_base::sync_with_stdio(0);cin.tie(0); + #define ll long long + #define endl "\n" + #define TEST int t;cin >> t;while(t--) + + int main() + { + ll n, money, sum=0, k=0, x=INT_MIN, c=1; + cin >> n >> money; + ll arr[n]; + for(ll i=0;i> arr[i]; + } + for(ll i=0;imoney) + { + sum=sum-arr[i+1-k]; + k--; + } + if(sum==money) + { + c=0; + cout << money << endl; + } + x=max(sum,x); + } + if(c==1) + cout << x << endl; + } + \ No newline at end of file diff --git a/LCMSUM.cpp b/LCMSUM.cpp new file mode 100644 index 0000000..68251d5 --- /dev/null +++ b/LCMSUM.cpp @@ -0,0 +1,85 @@ +/************ + + Author :- Profesor(Abhishek) + 2020-08-24-15.32.01 +**********/ +#include + +using namespace std; + +#define ll long long +#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +#define endl "\n" +#define fori(i,a,b) for(ll i=a;i=b;i--) +#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) +#define all(x) (x).begin(),(x).end() +#define allr(x) (x).rbegin(),(x).rend() +#define eb emplace_back +#define pb push_back +#define mp make_pair +#define fi first +#define se second +#define sll set +#define vll vector +#define msl map +#define mll map + +const ll MAXN = (ll)1e6; + +ll i, j, k; + +vll LCM(MAXN+1); +vector phi(MAXN+1); + +void phi_1_to_n() { + + phi[0] = 0; + phi[1] = 1; + for ( i = 2; i <= MAXN; i++) + phi[i] = i; + + for (i = 2; i <= MAXN; i++) { + if (phi[i] == i) { + for (j = i; j <= MAXN; j+=i) + phi[j] -= phi[j] / i; + } + } + + for(i = 1;i <= MAXN; i++){ + for( j = i; j <= MAXN; j+=i){ + LCM[j] += (i*phi[i]); + } + } +} + + + +int main() +{ + phi_1_to_n(); + fast; + ll t; + cin >> t; + while(t--) + { + ll n; + cin >> n; +// for(i=1; i*i + +using namespace std; + +#define ll long long +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define endl "\n" +#define fori(i,a,b) for(ll i=a;i=b;i--) +#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) +#define all(x) (x).begin(),(x).end() +#define allr(x) (x).rbegin(),(x).rend() +#define eb emplace_back +#define pb push_backbig +#define mp make_pair +#define fi first +#define se second +#define sll set +#define vll vector +#define msl map +#define mll map + +const ll big = 1e9+7; + +ll binary_exponentation(ll a, ll n) { + if(n == 0) + return 1; + if(n == 1) + return a%big; + ll r = binary_exponentation(a, n/2); + if(n % 2 == 0) { + return (r%big * r%big)%big; + } + else + return (r%big * r%big * a%big)%big; +} + + +ll i, j, k; +int main() +{ + ll t; + cin >> t; + while(t--) + { + ll n; + cin >> n; + if(n<3) + { + cout << n << endl; + continue; + } + + if(n%3==1) + { + cout << 4 * binary_exponentation(3 , (n-4)/3)%big << endl; + + } + else if(n%3==2) + { + + cout << 2 * binary_exponentation(3 , (n-2)/3)%big << endl; + } + else + { + cout << binary_exponentation(3 , n/3)%big << endl; + } + } + return 0; +} \ No newline at end of file diff --git a/NAJPWG.cpp b/NAJPWG.cpp new file mode 100644 index 0000000..f77ec08 --- /dev/null +++ b/NAJPWG.cpp @@ -0,0 +1,88 @@ +/************ + + Author :- Profesor(Abhishek) + 2020-08-24-15.32.01 +**********/ +#include + +using namespace std; + +#define ll long long +#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +#define endl "\n" +#define fori(i,a,b) for(ll i=a;i=b;i--) +#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) +#define all(x) (x).begin(),(x).end() +#define allr(x) (x).rbegin(),(x).rend() +#define eb emplace_back +#define pb push_back +#define mp make_pair +#define fi first +#define se second +#define sll set +#define vll vector +#define msl map +#define mll map + +const ll MAXN = (ll)1e5; + +ll i, j, k; + +vector phi(MAXN+1); + + + +void phi_1_to_n() { + + phi[0] = 0; + phi[1] = 1; + for ( i = 2; i <= MAXN; i++) + phi[i] = i; + + for (i = 2; i <= MAXN; i++) { + if (phi[i] == i) { + for (j = i; j <= MAXN; j+=i) + phi[j] -= phi[j] / i; + } + } + +} + +ll binary_exponentation(ll a, ll b) +{ + ll res=1; + while(b>0) + { + if(b&1) + res=res*a; + a=a*a; + b>>=1; + } + return res; +} + + + +int main() +{ + phi_1_to_n(); + fast; + ll t,x=0; + cin >> t; + ll ans[MAXN+1]; + for(i=1;i<=MAXN;i++) + { + ans[i]=ans[i-1]+(i-phi[i]); + } + while(t--) + { + x++; + ll n ; + cin >> n; + cout << "Case " << x << ": " << ans[n] << endl; + + + } + +} \ No newline at end of file diff --git a/ONP.cpp b/ONP.cpp new file mode 100644 index 0000000..56c9fb5 --- /dev/null +++ b/ONP.cpp @@ -0,0 +1,82 @@ +#include +#include + +using namespace std; + +#define ll long long +#define endl "\n" +#define fast ios_base::sync_with_stdio(0);cin.tie(0); + +int priority(char c) +{ + if(c=='^') + return 3; + else if(c=='*' || c== '/') + return 2; + else if(c=='+' || c== '-') + return 1; + else + return -1; +} + +void infixtopostfix(string s) +{ + stack st; + st.push('E'); + string res=""; + for( int i=0;i='a'&&s[i]<='z') + { + res+=s[i]; + } + else if(s[i]=='(') + { + st.push('('); + } + else if(s[i] == ')') + { + while(st.top() != 'E' && st.top() != '(') + { + char c=st.top(); + st.pop(); + res=res + c; + } + if(st.top() == '(') + { + st.pop(); // not added char c=st.top()???? + } + } + else + { + while(st.top()!='E' && priority(s[i]) <= priority(st.top())) + { + char c=st.top(); + st.pop(); + res+=c; + } + st.push(s[i]); + } + + } + while(st.top() != 'E') + { + char c=st.top(); + st.pop(); + res+=c; + } + cout << res << endl; +} + +int main() +{ + int t; + cin >> t; + while(t--) + { + string s; + cin >> s; + infixtopostfix(s); + } + return 0; +} \ No newline at end of file diff --git a/PALIN.cpp b/PALIN.cpp new file mode 100644 index 0000000..67a2247 --- /dev/null +++ b/PALIN.cpp @@ -0,0 +1,110 @@ +#include + +#include + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" + +int main() { + ll t, i, j; + cin >> t; + while (t--) { + ll counter = 0, p = 0, q = 0,c=0; + string s; + cin >> s; + s.erase(0, min(s.find_first_not_of('0'), s.size()-1)); + + if (s.length() == 1 && s != "9") { + if (s == "1") + cout << "2" << endl; + else if (s == "2") + cout << "3" << endl; + else if (s == "3") + cout << "4" << endl; + else if (s == "4") + cout << "5" << endl; + else if (s == "5") + cout << "6" << endl; + else if (s == "6") + cout << "7" << endl; + else if (s == "7") + cout << "8" << endl; + else if (s == "8") + cout << "9" << endl; + else if (s == "0") + cout << "1" << endl; + + continue; + } + for (i = 0; i < s.length(); i++) { + if (s[i] == '9') + counter++; + } + if (counter == s.length()) { + cout << stoi(s) + 2 << endl; + continue; + } + string y = s; + for (i = 0, j = s.length() - 1; i < j; i++, j--) { + if (s[i] == s[j]) + continue; + else if (s[i] != s[j]) { + s[j] = s[i]; + } + } + string x = s; + if (x < y || x==y) { + if (s.length() % 2 == 0) { + ll m = s.length() / 2; + p = m; + q = m - 1; + if (s[p] == '9' && s[q] == '9') { + while (s[p] == '9' && s[q] == '9') { + s[p] = '0'; + s[q] = '0'; + p++; + q--; + } + s[p] += 1; + s[q] += 1; + + cout << s << endl; + continue; + } + s[m-1] = s[m-1] + 1; + s[m] = s[m-1]; + } + else { + int m = (s.length() - 1) / 2; + + if (s[m] == '9') { + s[m] = '0'; + p = m - 1; + q = m + 1; + if (s[p] == '9' && s[q] == '9') { + while (s[p] == '9' && s[q] == '9') { + s[p] = '0'; + s[q] = '0'; + p--; + q++; + + } + s[p] += 1; + s[q] += 1; + + cout << s << endl; + continue; + } + } + + s[m] = s[m] + 1; + } + + } + cout << s << endl; + + } +} \ No newline at end of file diff --git a/PERMUT2.cpp b/PERMUT2.cpp new file mode 100644 index 0000000..eba2e2c --- /dev/null +++ b/PERMUT2.cpp @@ -0,0 +1,42 @@ +#include +#include +#include + +using namespace std ; +#define endl "\n" +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long + +int main () +{ + fast; + int n, i; + while(cin >> n&& n!=0) + { + int arr[n], c; + int invP[n]; + for(i=0;i> arr[i]; + invP[arr[i]-1]=i+1; + + } + + + for(i=0;i + +using namespace std; + +#define ll long long +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define endl "\n" +#define fori(i,a,b) for(ll i=a;i=b;i--) +#define forit(it,x) for (auto it=(x).begin();it!=(x).end(); it++) +#define all(x) (x).begin(),(x).end() +#define allr(x) (x).rbegin(),(x).rend() +#define eb emplace_back +#define pb push_back +#define mp make_pair +#define fi first +#define se second +#define sll set +#define vll vector +#define msl map +#define mll map + +ll i, j, k; + + +vector segmentedSieve(long long L, long long R) { + // generate all primes up to sqrt(R) + long long lim = sqrt(R); + vector mark(lim + 1, true); + mark[0]=mark[1]=false; + vector primes; + primes.emplace_back(2); + for (long long i = 3; i <= lim; i+=2) { + if (mark[i]) { + primes.emplace_back(i); + for (long long j = i * i; j <= lim; j += i) + mark[j] = false; + } + } + + vector isPrime(R - L + 1, true); + for (long long i : primes) + for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i) + isPrime[j - L] = false; + if (L == 1) + isPrime[0] = false; + return isPrime; +} + + +int main() +{ + fast; + ll t; + cin >>t; + while(t--) + { + ll l, r; + cin >> l >> r; + vectorp = segmentedSieve(l ,r); + for(i=l;i<=r;i++) + { + if(p[i-l]) + cout << i << endl; + } + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/QUADAREA.cpp b/QUADAREA.cpp new file mode 100644 index 0000000..f280443 --- /dev/null +++ b/QUADAREA.cpp @@ -0,0 +1,29 @@ + #include + using namespace std; + + #define ll long long int + #define endl "\n" + #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); + #define MOD 1000000007 + #define For(i,a,b) for(i=a;i> t; + while(t--) + { + double a, b, c, d; + cin >> a >> b >> c >> d; + double s=(a+b+c+d)/2; + // cout << s << endl; + double ans=(s-(double)a)*(s-(double)b)*(s-(double)c)*(s-(double)d); + // cout << ans << endl; + ans=sqrt(ans); + cout << fixed << setprecision(2) << ans << endl; + } + } + \ No newline at end of file diff --git a/SAMER08F.cpp b/SAMER08F.cpp new file mode 100644 index 0000000..8334db6 --- /dev/null +++ b/SAMER08F.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +#define fast ios_base::sync_with_stdio(0);cin.tie(0); +#define ll long long +#define endl "\n" + +int main() +{ + int n; + while(cin >> n) + { + if(n==0) + break; + + int x=n*(n+1)*(2*n+1)/6; + cout << x << endl; + + } + return 0; + +} \ No newline at end of file diff --git a/STPAR.cpp b/STPAR.cpp new file mode 100644 index 0000000..1a19b2e --- /dev/null +++ b/STPAR.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +using namespace std ; + +int main () +{ + int i , t , flag , n , arr[1002] ; + while (1){ + cin >> n ; + if (n == 0 ) + break ; + for (i = 0 ; i< n ; i++) + cin >> arr[i] ; + + stack mystack ; + + int counter = 1 ; + for (i = 0 ; i