Dan robocontest javoblari



Yüklə 0,58 Mb.
səhifə2/7
tarix07.01.2024
ölçüsü0,58 Mb.
#204426
1   2   3   4   5   6   7
2 5411487045807781686

30-masala
#include
using namespace std;
set b ;
set::iterator it ;
long long k ;
string s ="09" ;
void men(string a)
{
if(a.size()>0) { stringstream S; S<>k; int ss=0; b.insert(k); }
if(a.size()==13) { return ; }
else
{
if(a.size()!=0) men(a+"0"); men(a+"9");
}
}
int main()
{
men(""); long long a[501];
// for(it=b.begin();it!=b.end();it++) cout<<*it<<" ";
for(int i=1;i<501;i++){
long long s=0,l;
for(it=b.begin();it!=b.end();it++) if(*it%i==0) { s=1; l=*it ; break; }
if(s==1) a[i]=l ; else cout<}
int n,t; cin>>t;
for(int i=0;icin>>n;
cout<}
}

31-masala

#include


using namespace std;
int main(){
int n;
cin >> n;
int a,b,c;
int d1,d2;
while(n--){
cin >> a >> b >> c;
d1=b;
d2=a;
a=min(d1,d2);
b=max(d1,d2);
if ((ccout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
}
32-masala
#include
using namespace std;
int dp[1001][1001];
const int mod = 1e9+7;
int main(){
dp[0][0] = 1;
for(int n=1;n<=1000;n++){
dp[n][0] = 1;
for(int k =1;k<=1000;k++)
dp[n][k] = (dp[n-1][k] + dp[n][k-1])% mod;
}
int t , n , k;
cin >> t;
for(int i = 0; icin >> n >> k;
cout << dp[n][k] << "\n";
}
return 0;
}

33-masala
#include
using namespace std;
const long long MAX = 1000000;
vector primes;
void sieveSundaram()
{
bool marked[MAX/2 + 100] = {0};
for (int i=1; i<=(sqrt(MAX)-1)/2; i++)
for (int j=(i*(i+1))<<1; j<=MAX/2; j=j+2*i+1)
marked[j] = true;
primes.push_back(2);
for (int i=1; i<=MAX/2; i++)
if (marked[i] == false)
primes.push_back(2*i + 1);
}
bool isSmith(int n)
{
int original_no = n;
int pDigitSum = 0;
for (int i = 0; primes[i] <= n/2; i++)
{
while (n % primes[i] == 0)
{
int p = primes[i];
n = n/p;
while (p > 0)
{
pDigitSum += (p % 10);
p = p/10;
}
}
}
if (n != 1 && n != original_no)
{
while (n > 0)
{
pDigitSum = pDigitSum + n%10;
n = n/10;
}
}
int sumDigits = 0;
while (original_no > 0)
{
sumDigits = sumDigits + original_no % 10;
original_no = original_no/10;
}
return (pDigitSum == sumDigits);
}
int main()
{
long long n;
cin>>n;
sieveSundaram();
if (isSmith(n)) cout<<1;
else cout<<0;
return 0;
}

34-masala
#include
using namespace std;
int main(){
int a, b ,r;
cin >> a >> b;
r = 2 % b;
for(int i = 0; i < a; i++)
r = 1ll * r * r % b;
cout << r;
}

35-masala
#include
#include
#include
#include
using namespace std;
using ll = long long;
int main(){
vector v;
set s;
ll q;
for(int i = 0; i < 10; i++){
v.push_back(i);
s.insert(i);
}
ll d[19] = {1};
for(int i = 1; i <= 18; i++)
d[i] = d[i - 1] * 10;
for(int i = 1; i < v.size(); i++){
for(int l = 1; l <=18; l++){
q = v[i] * l;
if(q >= d[18]) break;
if(d[l-1] <= q and q < d[l] and s.find(q) == s.end()){
s.insert(q);
v.push_back(q);
}
}
}
sort(v.begin(), v.end());
ll t, l, r;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> l >> r;
cout << upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l) << '\n';
}
return 0;
}

37-masala
#include
#include
#define qol 1000000007
using namespace std;
int main()
{
long long T,n,k,x,a=1;
cin>>T;
for(int j=0;j{
cin>>n>>k;
if(n<=0 && k>=0)
{
x=k-n;
}
else { x=k-n+1; }
a=(a*x)%qol;
}
cout<}

39-masala

#include


#include
#define qol 1000000007
using namespace std;
int main()
{
long long T,n,k,x,a=1;
cin>>T;
for(int j=0;j{
cin>>n>>k;
if(n<=0 && k>=0)
{
x=k-n;
}
else { x=k-n+1; }
a=(a*x)%qol;
}
cout<}


41-masala
#include
#define int long
using namespace std;

int _mergeSort(int arr[], int temp[],


int left, int right);
int merge(int arr[], int temp[], int left,
int mid, int right);

int mergeSort(int arr[], int array_size)


{
int temp[array_size];
return _mergeSort(arr, temp, 0, array_size - 1);
}

int _mergeSort(int arr[], int temp[],


int left, int right)
{
int mid, inv_count = 0;
if (right > left) {
mid = (right + left) / 2;
inv_count += _mergeSort(arr, temp,
left, mid);
inv_count += _mergeSort(arr, temp,
mid + 1, right);
inv_count += merge(arr, temp, left,
mid + 1, right);
}
return inv_count;
}
int merge(int arr[], int temp[], int left,
int mid, int right)
{
int i, j, k;
int inv_count = 0;

i = left;


j = mid;
k = left;
while ((i <= mid - 1) && (j <= right)) {
if (arr[i] > 2 * arr[j]) {
inv_count += (mid - i);
j++;
}
else {
i++;
}
}

i = left;


j = mid;
k = left;

while ((i <= mid - 1) && (j <= right)) {


if (arr[i] <= arr[j]) {
temp[k++] = arr[i++];
}
else {
temp[k++] = arr[j++];
}
}

while (i <= mid - 1)


temp[k++] = arr[i++];

while (j <= right)


temp[k++] = arr[j++];

for (i = left; i <= right; i++)


arr[i] = temp[i];

return inv_count;


}
main()
{
int n;
cin >> n;
int arr[n];
for (int i=0; icin >> arr[i];
int ans = mergeSort(arr, n);
cout<< ans;
return 0;
}

42-masala
#include
#include
#include
#include

using namespace std;

string sarvar_tpy(const string& s) {
unordered_map p = {
{'+', 1}, {'-', 1}, {'*', 2}, {'/', 2}, {'^', 3}, {'(', -1}, {')', 0}
};
unordered_map a = {{'^', true}};
stack l;
string res;

for (char i : s) {


if (p.count(i)) {
if (i == '(') {
l.push(i);
} else {
while (!l.empty() && (p[l.top()] > p[i] || (p[l.top()] == p[i] && !a.count(i)))) {
res += l.top();
l.pop();
}
if (i == ')') {
l.pop();
} else {
l.push(i);
}
}
} else {
res += i;
}
}

while (!l.empty()) {


res += l.top();
l.pop();
}

return res;


}

int main() {


string s;
getline(cin, s);
cout << sarvar_tpy(s) << endl;

return 0;


}

43-masala
#include
using namespace std;
int main () {
long long a,b;
cin >> a;
cin >> b;
cout << b;
cout << " ";
cout << a;
}

44-masala
#include
using namespace std;
int main () {
int b;
cin >>b;
if (b>=1){
if (b%400==0 || b%4==0 && b%100!=0) {
cout <<"Kabisa yili";
}
else {
cout <<"Kabisa yili emas";
}
}
}

45-masala
#include
#include
using namespace std;
int main () {
long n,natija=0;
cin >> n;
if(n>=0 ) {
for (int i=0;i<=n;i++){
natija+=i;
}
cout << natija;
}

}

46-masala


#include
using namespace std ;
unsigned long long countSetBits(unsigned long long n)
{
unsigned long long count = 0;
while (n)
{
count += n & 1;
n >>= 1;
}
return count;
}
unsigned long long countOfOddsPascal(unsigned long long n)
{
unsigned long long c = countSetBits(n);
return pow(2, c);
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
unsigned long long n,s=0;
cin>>n;
if(n>=999995555)
{
s=499835944595520177;
for(long long i=999995556;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=998877665)
{
s=498719015602673418;
for(long long i=998877666;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=987654321)
{
s=487575809094254002;
for(long long i=987654322;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=980000000)
{
s=480047415811308376;
for(long long i=980000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=960000000)
{
s=460652501031541896;
for(long long i=960000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=950000000)
{
s=451104202453626328;
for(long long i=950000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=940000000)
{
s=441655108204374088;
for(long long i=940000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=920000000)
{
s=423065854983982784;
for(long long i=920000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=912345678)
{
s=416055149464921335;
for(long long i=912345679;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=900000000)
{
s=404871320598811920;
for(long long i=900000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=880000000)
{
s=387074900489753104;
for(long long i=880000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=860000000)
{
s=369679461534637000;
for(long long i=860000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=840000000)
{
s=352682199302653320;
for(long long i=840000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=820000000)
{
s=336084822186612808;
for(long long i=820000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=800000000)
{
s=319890614427045260;
for(long long i=800000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=780000000)
{
s=304097815199669772;
for(long long i=780000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=760000000)
{
s=288703126147540892;
for(long long i=760000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=740000000)
{
s=273705896858077564;
for(long long i=740000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=720000000)
{
s=259111047907859684;
for(long long i=720000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=700000000)
{
s=244913877304646156;
for(long long i=700000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=680000000)
{
s=231115733899340276;
for(long long i=680000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=670000000)
{
s=224367083542821176;
for(long long i=670000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=660000000)
{
s=217719976839928856;
for(long long i=660000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=650000000)
{
s=211171707008944616;
for(long long i=650000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i); }
}
else if(n>=640000000)
{
s=204722805315088520;
for(long long i=640000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=620000000)
{
s=192125354136061976;
for(long long i=620000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=600000000)
{
s=179927283459995292;
for(long long i=600000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=580000000)
{
s=168129269352999524;
for(long long i=580000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=570000000)
{
s=162379815474264296;
for(long long i=570000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=560000000)
{
s=156730595874032032;
for(long long i=560000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=540000000)
{
s=145731336842970692;
for(long long i=540000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=520000000)
{
s=135140640902252942;
for(long long i=520000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=500000000)
{
s=124946796154402846;
for(long long i=500000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=480000000)
{
s=115150833917179950;
for(long long i=480000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=470000000)
{
s=110401702969791022;
for(long long i=470000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=460000000)
{
s=105755285224658198;
for(long long i=460000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=440000000)
{
s=96758300383245574;
for(long long i=440000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=420000000)
{
s=88160733310884270;
for(long long i=420000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=400000000)
{
s=79963538342345690;
for(long long i=400000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=380000000)
{
s=72167708905844234;
for(long long i=380000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=370000000)
{
s=68418632471025514;
for(long long i=370000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=360000000)
{
s=64770349482618530;
for(long long i=360000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=340000000)
{
s=57771911469777362;
for(long long i=340000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=320000000)
{
s=51174268598362670;
for(long long i=320000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=300000000)
{
s=44975761303331082;
for(long long i=300000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=280000000)
{
s=39176865431343670;
for(long long i=280000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=270000000)
{
s=36427112415984770;
for(long long i=270000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=260000000)
{
s=33780213764073392;
for(long long i=260000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=240000000)
{
s=28783611425725968;
for(long long i=240000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=220000000)
{
s=24186100237743064;
for(long long i=220000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=200000000)
{
s=19987846214112500;
for(long long i=200000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}else if(n>=180000000)
{
s=16190116584204812;
for(long long i=180000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=160000000)
{
s=12791422946120720;
for(long long i=160000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=150000000)
{
s=11241920509443012;
for(long long i=150000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=140000000)
{
s=9792288547114216;
for(long long i=140000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=130000000)
{
s=8443404653013542;
for(long long i=130000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=120000000)
{
s=7194537201907974;
for(long long i=120000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=115000000)
{
s=6607531787458382;
for(long long i=115000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=110000000)
{
s=6045366800908894;
for(long long i=110000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=100000000)
{
s=4995948788034770;
for(long long i=100000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=90000000)
{
s=4046705573066906;
for(long long i=90000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=85000000)
{
s=3609379123027178;
for(long long i=85000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=75000000)
{
s=2809806873980322;
for(long long i=75000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=50000000)
{
s=1248649621008860;
for(long long i=50000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else if(n>=25000000)
{
s=312049886166890;
for(long long i=25000001;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
else
{
for(long long i=1;i<=n;i++)
{
s=s+i+1-countOfOddsPascal(i);
}
}
cout<}


Yüklə 0,58 Mb.

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