- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M 1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- int main(){
- int t, cs = 0;
- LL x1, x2, y1, y2;
- LL a, b;
- scanf("%d", &t);
- while(t--){
- scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
- LL p, q;
- if(x1 < 0 && x2 < 0)p = abs(abs(x1)-abs(x2));
- else if(x1 >= 0 && x2 >= 0)p = abs(x1-x2);
- else if(x1 < 0 && x2 >= 0)p = abs(x1)+x2;
- else p = x1+abs(x2);
- if(y1 < 0 && y2 < 0)q = abs(abs(y1)-abs(y2));
- else if(y1 >= 0 && y2 >= 0)q = abs(y1-y2);
- else if(y1 < 0 && y2 >= 0)q = abs(y1)+y2;
- else q = y1+abs(y2);
- LL ans = __gcd(p, q)+1;
- printf("Case %d: %lld\n", ++cs, ans);
- }
- return 0;
- }
Sunday, February 28, 2016
LightOJ - 1077 - How Many Points?
LightOJ - 1067 - Combinations
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M (long long)1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- LL factorial[M+3];
- void findFact(){
- factorial[0] = 1;
- for(int i = 1; i < S; i++){
- factorial[i] = factorial[i-1] * i;
- factorial[i] %= M;
- }
- }
- LL modInverse(LL a, LL p){
- if(p == 0)return 1LL;
- else if(p%2)return ((a%M)*(modInverse(a, p-1)%M))%M;
- else{
- LL x = modInverse(a, p/2);
- return (x%M*x%M)%M;
- }
- }
- int main(){
- memset(factorial, 1LL, sizeof(factorial));
- findFact();
- int t, cs = 0;
- LL n, k;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &n, &k);
- LL y = factorial[n];
- LL z = (factorial[n-k]%M*factorial[k]%M)%M;
- LL ans = modInverse(z, M-2LL);
- ans = (y%M*ans%M)%M;
- printf("Case %d: %lld\n", ++cs, ans);
- }
- return 0;
- }
LightOJ - 1045 - Digits of Factorial
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define ll long long
- #define S 1000003
- using namespace std;
- double cuS[S];
- void cumulativeSum(){
- cuS[1] = log((double)1);
- for(int i = 2; i < S; i++){
- cuS[i] = cuS[i-1] + log((double)i);
- }
- }
- int main(){
- int t, cs = 0, n, base;
- cumulativeSum();
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &n, &base);
- double value = cuS[n];
- value /= log((double)base);
- ll ans = value;
- ans += 1;
- printf("Case %d: %lld\n", ++cs, ans);
- }
- return 0;
- }
LightOJ - 1035 - Intelligent Factorial Factorization
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define ll long long
- #define S 103
- using namespace std;
- int prime[S];
- int primeNum[S];
- int ans[S];
- int ind;
- void seive(){
- int sqr = sqrt(S);
- for(int i = 2; i <= sqr; i++){
- if(prime[i]){
- for(int j = i+i; j < S; j+=i)prime[j] = 0;
- }
- }
- ind = 0;
- for(int i = 2; i < S; i++)if(prime[i])primeNum[ind++] = i;
- }
- void numDivisor(int number){
- int cn = 0;
- for(int i = 0; i < ind; i++){
- for(int k = 2; k <= number; k++){
- while(prime[k]%primeNum[i] == 0){
- cn++;
- prime[k] /= primeNum[i];
- }
- ans[primeNum[i]] += cn;
- cn = 0;
- }
- }
- }
- int main(){
- int t, cs = 0, n;
- memset(prime, 1, sizeof(prime));
- seive();
- scanf("%d", &t);
- while(t--){
- scanf("%d", &n);
- memset(ans, 0, sizeof(ans));
- for(int i = 2; i < S; i++)prime[i] = i;
- numDivisor(n);
- printf("Case %d:", ++cs);
- bool flag = true;
- for(int i = 2; i <= 100; i++){
- if(ans[i] && flag)printf(" %d = %d (%d)", n, i, ans[i]), flag = false;
- else if(!flag && ans[i])printf(" * %d (%d)", i, ans[i]);
- }
- puts("");
- }
- return 0;
- }
LightOJ - Trailing Zeroes (I)
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define ll long long
- #define S 1000003
- using namespace std;
- bool prime[S];
- ll primeNum[S];
- int ind;
- void seive(){
- prime[0] = prime[1] = false;
- int sqr = sqrt(S);
- for(int i = 2; i <= sqr; i++){
- if(prime[i]){
- for(int j = i+i; j <= S; j+=i)prime[j] = false;
- }
- }
- ind = 0;
- for(int i = 0; i <= S; i++)if(prime[i])primeNum[ind++] = i;
- }
- ll numDivisor(ll raw){
- ll tot = 0, prev = 0LL, cn = 0LL;
- for(int i = 0; i < ind && primeNum[i]*primeNum[i] <= raw; i++){
- bool flag = true;
- while(raw%primeNum[i] == 0LL){
- cn++;
- raw /= primeNum[i];
- }
- tot = (prev*cn) + (prev+cn);
- prev = tot;
- if(raw != 1)cn = 0LL;
- }
- if(!cn)tot += tot + 1;
- return tot;
- }
- int main(){
- int t, cs = 0;
- memset(prime, true, sizeof(prime));
- seive();
- ll n;
- scanf("%d", &t);
- while(t--){
- scanf("%lld", &n);
- if(n == 1LL){
- printf("Case %d: 0\n", ++cs);
- continue;
- }
- ll ans = numDivisor(n);
- printf("Case %d: %lld\n", ++cs, ans);
- }
- return 0;
- }
Friday, February 26, 2016
LightOJ - 1014 - Ifter Party
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int t, P, L, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &P, &L);
- int Q = P-L;
- printf("Case %d: ", ++cs);
- if(L >= Q){
- puts("impossible");
- continue;
- }
- int sqr = sqrt(Q);
- vector <int> container;
- for(int i = 1; i <= sqr; i++){
- if(Q%i == 0){
- if(L < i)container.push_back(i);
- int p = Q/i;
- if(p != i && L < p)container.push_back(p);
- }
- }
- sort(container.begin(), container.end());
- int sz = container.size();
- if(sz == 0)puts("impossible");
- else{
- for(int i = 0; i < sz; i++){
- printf("%d", container[i]);
- if(i == sz-1)puts("");
- else printf(" ");
- }
- }
- }
- return 0;
- }
Subscribe to:
Posts (Atom)