Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number Painting #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions K.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def gcd(a,b):
if(a==0):
return b
else:
return gcd(b%a,a)

from math import *
k,n=map(int,input().split())
if(k==n-1):
print(0)
elif(k==n):
print('1/'+str(factorial(n)))
else:
fact=[1,1,2]
for i in range(3,max(n-k,k)+1):
fact.append(fact[-1]*i)

if((n-k)%2==0):
num=1
else:
num=-1
prod=1
for i in range(n-k,0,-1):
prod*=i
if(i%2==1):
num+=prod
else:
num-=prod

den=fact[k]*fact[n-k]

g=gcd(num,den)
num=num//g
den=den//g
print(str(num)+"/"+str(den))
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

int modulo = 1e9 + 7;

int fpow(int a, int n) {
int ans = 1;
while (n) {
if (n&1) ans = (ans*a)%modulo;
a = (a*a)%modulo; n = n >> 1;
}
return ans;
}

signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int n; cin >> n;
int ans[n];
int y = 0;
For(i,0,n) {
int num = i+1;
int val = 1;
for (int j = 1; j <= sqrt(num); ++j) {
if (num%j == 0 and j != num) {
val = max(val, ans[j-1]+1);
int x = num/j;
if (x != num)
val = max(val, ans[x-1]+1);
}
}
ans[i] = val;
y = max(y, ans[i]);
}
cout << y << endl;
printarr(ans,n);
return 0;
}