1-masala #include using namespace std; int main { long long a,b; cin>>a>>b; cout



Yüklə 98,62 Kb.
səhifə3/7
tarix14.12.2023
ölçüsü98,62 Kb.
#178512
1   2   3   4   5   6   7
100ta masala cpp

47-masala

#include


#define ll long long
using namespace std;
string to2(int n)
{
string r;
while (n != 0){
r += ( n % 2 == 0 ? "0" : "1" );
n /= 2;
}

return r;


}
int main() {

int t;
cin>>t;


while(t--){

int n,ans=0; string m;


cin>>n;
m=to2(n);

for(int i=0;i
if(m[i]=='1')ans++;
}
cout<return 0;
}

48-masala
#include
using namespace std;
int main () {
int n,re=1;
cin >>n;
for (int i=1;i<=n;i++) {
for (int j = 1; j <= i; j++) {
cout<re++;
}
cout<<"\n";
}
}

49-masala


#include
#define ll long long
using namespace std;

int main()


{
ll t,n=0,number,natija=0;
cin>>t;
while(t--){
n=0;
natija=0;
cin>>number;
for(ll i=0; i<=10000;i++){
n=n+i;
if(n==number){
natija = natija+1;
}
}
if(natija==1){
cout<<1;
}
else cout<<0;
}
return 0;
}

52-masala
#include
#include
using namespace std;
int main() {
int a,n=0;
cin>>a;
vectorA,w(a);
for(int i=0; ifor(int i=1; i<=a; i++) {
n+=i;
n%=A.size();
w[A[n]]=i;
A.erase(A.begin()+(n));
}
for(int i=0; i}

53-masala

#include


using namespace std;
int main () {
long int N;
cin >> N;
if (N>2) {
cout<}
else {
cout<<0;
}
return 0;

}


54-masala
#include
using namespace std;
int main() {
long long n;
cin >> n;

if (n % 2 == 0) {


cout << "Husan" << endl;
} else {
cout << "Hasan" << endl;
}

return 0;


}

55-masala
#include

int main() {


int t;
std::cin >> t;

for (int i = 0; i < t; i++) {


long long n;
std::cin >> n;
std::cout << n * n * n + n << std::endl;
}

return 0;


}


56-masala
#include
#include
#include

int main() {


std::vector l;
l.push_back(0);

for (int i = 0; i < 39; i++) {


for (int j = 0; j < 59; j++) {
for (int k = 0; k < 64; k++) {
l.push_back(pow(3, j) * pow(5, i) * pow(2, k));
}
}
}

std::sort(l.begin(), l.end());

int t;
std::cin >> t;

while (t > 0) {


int a;
std::cin >> a;
std::cout << l[a] << std::endl;
t--;
}

return 0;


}

58-masala
#include
using namespace std;
int main () {
int a;
cin >>a;
cout << 7-a;
}

59-masala
#include
using namespace std;
int main(){
long long a;
cin >> a;
cout << a*a;
return 0;
}

61-masala

#include

int main() {
long long n;
std::cin >> n;

long long result = n * (2 * n - 1);

std::cout << result << std::endl;

return 0;


}

62-masala

#include

int main() {
long long n;
std::cin >> n;

long long result = (n * n + n + 2) / 2;

std::cout << result << std::endl;

return 0;


}

63-masala
#include
#define ll long long
using namespace std;

const ll MOD = 1e9+7;


ll n,m,p=1;

// base^p


ll bin_pow(ll base, ll p) {
if (p<2) return base;
if (p%2) return bin_pow(base, p-1)*base%MOD;
ll t = bin_pow(base, p/2);
return t*t%MOD;
}

// (a/b) mod m


ll divide(ll a, ll b) {
return a*bin_pow(b, MOD - 2)%MOD;
}

int main(){


cin>>n>>m;
n--,m--;
for(;n;n--) p=p*divide(n+m,n)%MOD;
for(;m;m--) p=p*divide(m, m)%MOD;
cout<
}

66-masala
#include
using namespace std;
int main() {
long long n;
cin >> n;

long long result = n / 2 + 1;

cout << result << endl;

return 0;


}

68-masala
#include
#include
#include

using namespace std;

int main() {
int n;
cin >> n;

vector a(n);


for (int i = 0; i < n; ++i) {
cin >> a[i];
}

int k;
cin >> k;

sort(a.begin(), a.end());

cout << a[k - 1] << endl;

return 0;
}

69-masala
#include
using namespace std;
#define mx 100005
vectoradj[mx];
bool vis[mx];
long long d;

void dfs(int u, int s) {


vis[u] = true;
for (auto x : adj[u]) {
if (vis[x] == false) {
d += s+1;
dfs(x, s+1);
}
}
}

void add(int u, int v)


{
adj[u].push_back(v);
adj[v].push_back(u);
}
int main()
{
int n, m;
cin >> n ;
int a[n+1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i=1; i<=n; i++)
{
if (a[i] == -1) add(i, 0);
else add(i, a[i]);
}
dfs(0,0);
cout << d;
}


70-masala
#include
#include

const long long MOD = 1000000007;

long long gcd(long long a, long long b) {
return (b == 0) ? a : gcd(b, a % b);
}

long long fib(long long n) {


std::vector> a = {{0, 1}, {1, 1}};
std::vector> r = {{1, 0}, {0, 1}};

auto mult = [](const std::vector>& x, const std::vector>& y) {


std::vector> result(2, std::vector(2, 0));
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
result[i][j] = (result[i][j] + x[i][k] * y[k][j]) % MOD;
}
}
}
return result;
};

while (n > 0) {


if (n % 2 == 1) {
r = mult(r, a);
}
n = n / 2;
a = mult(a, a);
}

return r[1][0];


}

int main() {


long long a, b;
std::cin >> a >> b;

long long result = fib(gcd(a, b));

std::cout << result << std::endl;

return 0;


}

71-masala
#include

int main() {


long long n;
std::cin >> n;

long long x = (n / 2) + 1;

std::cout << x << std::endl;

return 0;


}


72-masala
#include
#include

int main() {


int x1, y1, x2, y2, x3, y3;
std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

double a = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));


double b = sqrt(pow(x3 - x1, 2) + pow(y3 - y1, 2));
double c = sqrt(pow(x3 - x2, 2) + pow(y3 - y2, 2));

if (a + b > c && a + c > b && b + c > a) {


std::cout << "uchburchak" << std::endl;
} else {
std::cout << "uchburchak emas" << std::endl;
}

return 0;


}


73-masala
#include

long long Fib_Last_Digit(long long n) {


if (n == 0) return 0;
else if (n == 1) return 1;
else {
long long a = 0, b = 1, c;
for (long long i = 1; i < n; ++i) {
c = (a + b) % 10;
a = b;
b = c;
}
return c;
}
}

int main() {


int t;
std::cin >> t;

for (int i = 0; i < t; ++i) {


long long n;
std::cin >> n;

if (n > 60) {


n %= 60;
}

std::cout << Fib_Last_Digit(n) << std::endl;


}

return 0;


}

74-masala
#include

#include

using namespace std;

int const mod = 1e9+7;

long long binpow(long long a, long long b, long long m){

if(b == 0) return 1;


long long k = binpow(a, b / 2, m) % m;

k *= k;

k %= m;


if(b % 2 == 1) return (a * k) % m;

return k;

}

long long binpow1(long long a, long long b, long long m) {



a %= m;

long long res = 1;

while (b > 0) {

if (b & 1)

res = res * a % m;

a = a * a % m;

b >>= 1;

}

return res;



}

long long cnr(long long a, long long b, long long m){

long long t = 1, d = 1;

for(int i = 1; i <= b; i ++){

t = (t * i) % m;

d = (d * (a - i + 1)) % m;

}

return ((d * binpow(t, (m - 2), m))) % m;



}

int main(){

long long n; cin >> n;

long long d = cnr((2 * n), n, mod); d *= binpow1(n + 1, mod - 2, mod); cout << d % mod << endl;

return 0;

}


75-masala
#include
#include
using namespace std;
vector helper;
long long inv_count(vector&a , int l , int r){
if(l >= r - 1 ) return 0;
int m = (l + r) / 2;
long long x= inv_count (a , l , m);
long long y = inv_count(a , m , r);
long long q=0;
for(int i= l , j= m ; i < m; i++){
while(j < r && a[i] > a[j]) j++;
q+=j - m;
}
for(int k=l , i=l , j=m; k < r; k++){
helper[k]=a[i==m ? j++ :j == r ? i++:a[i]}
for(int i=l ; i < r ; i++)
a[i]=helper[i];
return q + x +y;
}
int main (){
int n;
cin>>n;
vector a(n);
for(int i=0 ; i < n ; i++)
cin>>a[i];
helper.resize(n);
cout<return 0;
}


78-masala
#include
#include

int main() {


int n, k;
std::cin >> n >> k;

std::vector arr(n);


for (int i = 0; i < n; ++i) {
std::cin >> arr[i];
}

int s = 0;


for (int i = 0; i < n; ++i) {
s += arr[i];
if (s - k < 0) {
s = 0;
} else {
s = s - k;
}
}

if (s < 0) {


std::cout << 0 << std::endl;
} else {
std::cout << s << std::endl;
}

return 0;


}


80-masala
#include

using namespace std;

int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; long long s = 0; cin >> n;
vector a(2 * n);
for(int &x: a){
cin >> x; s += x;
}
int inf = s / n;
vector divs;
for(int i = 1, j; 1LL * i * i <= s; i ++){
if(s % i == 0){
divs.push_back(i);
j = s / i;
if(i != j && j <= inf) divs.push_back(j);
}
}
sort(divs.rbegin(), divs.rend());
int i = -1, mod, l, r;
vector b(2 * n);
while(true){
mod = divs[++ i];
for(int i = 0; i < 2 * n; i ++) b[i] = a[i] % mod;
sort(b.begin(), b.end());
l = 0; r = 2 * n - 1;
while(l <= r && b[l] == 0) l ++;
if(l % 2 != 0) continue;
while(l < r && b[l]+b[r] == mod) l ++, r --;
if(l < r) continue;
break;
}
cout << divs[i] << endl;
return 0;
}


82-masala
#include
#include

int main() {


int s, t, a, b, m, n;
std::cin >> s >> t >> a >> b >> m >> n;

std::vector d(m);


for (int i = 0; i < m; ++i) {
std::cin >> d[i];
}

std::vector d1(n);


for (int j = 0; j < n; ++j) {
std::cin >> d1[j];
}

int x = 0;


int y = 0;

for (const auto &i : d) {


if (i >= (s - a) && i <= (t - a)) {
x += 1;
}
}

for (const auto &j : d1) {


if (j <= (t - b) && j >= (s - b)) {
y += 1;
}
}

std::cout << x << std::endl;


std::cout << y << std::endl;

return 0;


}

83-masala
#include
#include

int main() {


int s, t, a, b, m, n;
std::cin >> s >> t >> a >> b >> m >> n;

std::vector d(m);


for (int i = 0; i < m; ++i) {
std::cin >> d[i];
}

std::vector d1(n);


for (int j = 0; j < n; ++j) {
std::cin >> d1[j];
}

int x = 0;


int y = 0;

for (const auto &i : d) {


if (i >= (s - a) && i <= (t - a)) {
x += 1;
}
}

for (const auto &j : d1) {


if (j <= (t - b) && j >= (s - b)) {
y += 1;
}
}

std::cout << x << std::endl;


std::cout << y << std::endl;

return 0;


}

84-masala
#pragma GCC optimize("Ofast")
#include
using ll = long long;
#define vi vector
#define vc vector
#define pb push_back
#define rep(i, a, b) for(ll i = (a); i != (b); i += 2 * ((a) < (b)) - 1)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(0);

using namespace std;


const int mod = 1e9 + 7;

int main(){ fast


ll n, m, r; cin >> n >> m >> r; ll a[n][m], b[n][m];
rep(i, 0, n)
rep(j, 0, m)
cin >> a[i][j];
ll left = 0, right = m - 1, up = 0, down = n - 1;
while(left <= right && up <= down){
vi frame;
rep(i, up, down)
frame.pb(a[i][left]);
rep(i, left, right)
frame.pb(a[down][i]);
rep(i, down, up)
frame.pb(a[i][right]);
rep(i, right, left)
frame.pb(a[up][i]);
ll len = frame.size();
ll ind = 0;
rep(i, up, down)
//frame.pb(a[i][left]);
a[i][left] = frame[(ind++ - r % len + len) % len];
rep(i, left, right)
//frame.pb(a[down][i]);
a[down][i] = frame[(ind++ - r % len + len) % len];
rep(i, down, up)
//frame.pb(a[i][right]);
a[i][right] = frame[(ind++ - r % len + len) % len];
rep(i, right, left)
//frame.pb(a[up][i]);
a[up][i] = frame[(ind++ - r % len + len) % len];
left++; right--;
up++; down--;
}
rep(i, 0, n)
rep(j, 0, m)
cout << a[i][j] << " \n"[j == m - 1];
cout << endl;
return 0;
}

Yüklə 98,62 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin