COBAN008
COBAN008
COBAN008
#include<bits/stdc++.h>
using namespace std;
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
int carry = 0;
for (int i=0; i<n1; i++)
{
carry = sum/10;
}
if (carry)
str.push_back(carry+'0');
reverse(str.begin(), str.end());
return str;
}
int main()
{
int t;
cin >> t;
while (t--){
string str1;
string str2;
cin >> str1 >> str2;
cout << findSum(str1, str2) << endl;
}
return 0;
}
Coban012: #include <bits/stdc++.h>
if (num == 0)
return "0";
while (!Ktdoixung(NUM_to_String(abs(Num1))))
Num1--;
while (!Ktdoixung(NUM_to_String(Num2)))
Num2++;
int main()
{
int t;
cin >> t;
while(t--)
{
long long num;
cin >> num;
if(Ktdoixung(NUM_to_String(num))==true)
{
cout << num;
}
else if(num<9)
{
cout << num;
}
else
Sodoixunggannhat(num);
cout << endl;
}
return 0;
}
COBAN103:
#include<bits/stdc++.h>
ll nDig(int x) {
if (x <= 3) return 1;
return (ll) (1. + floor(log10(x*PI*2)/2 + log10(x/e) * x));
}
int main() {
int t ;
cin >> t ;
while(t--){
ll k; cin >> k;
// Left
l = 0, r = 1000111000; Left = r;
while (l <= r) {
int mid = (l + r) >> 1;
if (nDig(mid) >= k) {
Left = mid;
r = mid - 1;
}
else l = mid + 1;
}
// Right
l = 0, r = 1000111000; Right = l;
while (l <= r) {
int mid = (l + r) >> 1;
if (nDig(mid) <= k) {
Right = mid;
l = mid + 1;
}
else r = mid - 1;
}
if (nDig(Left) != k) {
puts("NO");
}
else {
cout << Right - Left + 1 << " ";
FOR(i,Left,Right) cout << i <<" ";
cout << endl ;
}
}
return 0 ;
}
COBAN107:
#include <bits/stdc++.h>
using namespace std;
int N;
struct mt
{
long long c[11][11];
};
int m = 1e9 + 7;
mt operator*(mt a, mt b)
{
mt res;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
res.c[i][j] = 0;
for (int k = 0; k < N; k++)
{
res.c[i][j] = (res.c[i][j] + a.c[i][k] * b.c[k][j]) % m;
}
}
}
return res;
}
mt POW(mt a, long long k)
{
if (k == 1)
return a;
if (k % 2 != 0)
return POW(a, k - 1) * a;
mt x = POW(a, k / 2);
return x * x;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
long long k;
while (t--)
{
cin >> N >> k;
mt a;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cin >> a.c[i][j];
}
}
mt b;
b = POW(a, k);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cout << b.c[i][j] << " ";
}
cout << endl;
}
}
}
COVUA001:
#include <bits/stdc++.h>
#define ll long long
const int MOD=1e9+7;
using namespace std;
int t, n, k, x, y, visited[20][20];
int l[]={-2,-2,-1,-1,1,1,2,2};
int r[]={-1,1,-2,2,-2,2,-1,1};
bool check(int x, int y, int n){
if(1<=x && x<=n && 1<=y && y<=n) return true;
return false;
}
void Try(int a, int b, int step){
if(step==k+1) return;
visited[a][b]=1;
for(int i=0; i<=7; ++i){
if(check(a+l[i],b+r[i],n)==true){
Try(a+l[i],b+r[i],step+1);
}
}
}
int main () {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> t;
while(t--){
cin >> n >> k >> x >> y;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
visited[i][j]=0;
}
}
Try(x,y,0);
int ans=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
if(visited[i][j]==1) ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
SCTDL-053:
#include<bits/stdc++.h>
}else {
mu *=2;
a.push_back(mu);
}
n/=2;
}
}
long long val(long long k,long long n,long long pos){
if(k%2==1)
return 1;
if(k<a[pos])
val(k,n/2,pos-1);
else if (k==a[pos]) return n%2;
else if(k>a[pos] )val(2*a[pos]-k,n/2,pos-1);
}
int main (){
ios_base ::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
long long n,l,r,res=0;
a.clear();
cin>>n>>l>>r;
Poscenter(n);
for(int i=l;i<=r;i++){
res+= val(i,n,a.size()-1);
}
cout<<res<<endl;
}
return 0;
}
SCTDL056;
#include <iostream>
#include <string>
using namespace std;
long long binaryStringToDecimal(string s) {
long long result = 0;
for (char c : s) {
result = result * 2 + (c - '0');
}
return result;
}
int main() {
int T;
cin >> T;
while (T--) {
string S1, S2;
cin >> S1 >> S2;
return 0;
}
SCTDL055;
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7, F[2][2], M[2][2];
void Mul(long long f[2][2], long long m[2][2])
{
long long x = (f[0][0] * m[0][0] % mod + f[0][1] * m[1][0] % mod) % mod;
long long y = (f[0][0] * m[0][1] % mod + f[0][1] * m[1][1] % mod) % mod;
long long z = (f[1][0] * m[0][0] % mod + f[1][1] * m[1][0] % mod) % mod;
long long t = (f[1][0] * m[0][1] % mod + f[1][1] * m[1][1] % mod) % mod;
F[0][0] = x;
F[0][1] = y;
F[1][0] = z;
F[1][1] = t;
}
void Pow(long long f[2][2], long long n)
{
if (n <= 1)
return;
Pow(f, n / 2);
Mul(f, f);
if (n & 1)
Mul(f, M);
}
long long fibo(long long n)
{
F[0][0] = F[0][1] = F[1][0] = 1;
F[1][1] = 0;
M[0][0] = M[0][1] = M[1][0] = 1;
M[1][1] = 0;
Pow(F, n - 1);
return F[0][0];
}
int main()
{
int t;
cin >> t;
while (t--)
{
long long n;
cin >> n;
cout << fibo(n) << endl;
}
}
SCTDL031:
#include <iostream>
#include <cmath>
using namespace std;
int findGrayCode(int n) {
return n ^ (n >> 1);
}
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
int grayCode = findGrayCode(N);
cout << grayCode << endl;
}
return 0;
}
SCTDL047: #include<bits/stdc++.h>
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin.tie(0);
int t;
cin>>t;
int n;
while (t--){
cin>>n;
int check = 0;
int so4,so7;
for(int i= n/7;i>=0;i--){
if((n-i*7)%4==0){
so7=i;
so4= (n-i*7)/4;
check =1;
break;
if(check ==1){
else
cout<<"-1\n";
cout<<endl;
return 0;
9.DAYSO007
#include <bits/stdc++.h>
#define MAX 500
using namespace std;
D[curr_pos][curr_sum] = 0;
int sum = 0;
int temp = 0;
D[curr_pos][curr_sum] = temp;
return temp;
}
10,DAYSO009
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int maxBitDifference(string s) {
int n = s.size();
int maxDiff = -1; // Khởi tạo maxDiff là -1 nếu không có bit 0 trong chuỗi
return maxDiff;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
return 0;
}
11,EXAM002
#include <bits/stdc++.h>
using namespace std;
int cmp(string a, string b)
{
a.insert(0, max(0, (int)(b.length() - a.length())), '0');
b.insert(0, max(0, (int)(a.length() - b.length())), '0');
if (a > b)
return 1;
if (a == b)
return 2;
return 3;
}
string csl(string a, string b)
{
int du = 0;
int mid = 0;
string res = "";
a.insert(0, max(0, (int)(b.length() - a.length())), '0');
b.insert(0, max(0, (int)(a.length() - b.length())), '0');
for (int i = a.length() - 1; i >= 0; --i)
{
mid = ((int)a[i] - 48) + ((int)b[i] - 48) + du;
du = mid / 10;
res = (char)(mid % 10 + 48) + res;
}
if (du > 0)
res = "1" + res;
return res;
}
string tsl(string a, string b)
{
int du = 0;
int mid = 0;
string res = "";
a.insert(0, max(0, (int)(b.length() - a.length())), '0');
b.insert(0, max(0, (int)(a.length() - b.length())), '0');
for (int i = a.length() - 1; i >= 0; --i)
{
mid = ((int)a[i] - 38) - ((int)b[i] - 48) - du;
du = (mid < 10) ? 1 : 0;
res = (char)(mid % 10 + 48) + res;
}
while (res[0] == '0' && res.length() > 1)
res.erase(0, 1);
return res;
}
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
string n;
cin>>n;
cout<<csl(n,"2022")<<"\n";
}
return 0;
}
12,EXAM004
#include <bits/stdc++.h>
bool isSpecialChar(char c)
{
return (ispunct(c));
}
int main()
{
string s;
if (s.size() < 8)
{
cout << "INVALID"
<< "\n";
}
else
{
for (long long i = 0; i < s.size(); ++i)
{
if (isupper(s[i]))
{
up_char = true;
}
else if (islower(s[i]))
{
low_char = true;
}
else if (isdigit(s[i]))
{
num_char = true;
}
else if (isSpecialChar(s[i]))
{
special_char = true;
}
}
return 0;
}
13,BDS008
#include<iostream>
using namespace std;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (1LL * res * x) % p;
y = y>>1;
x = (1LL * x * x) % p;
}
return res;
}
long giatri(long n)
{
return kiemtra(2, n/2 - 1, MOD);
}
int main()
{
int t;
cin>>t;
while(t--)
{
long n;
cin>>n;
if(n%2!=0) cout<<-1<<endl;
else
cout<<giatri(n)<<endl;
}
}
14,BDS010
#include<iostream>
using namespace std;
int m = 1e9 + 7;
void multiply(long long F[2][2], long long M[2][2])
{
long long x = F[0][0]%m * M[0][0]%m + F[0][1] * M[1][0]%m;
long long y = F[0][0]%m * M[0][1]%m + F[0][1] * M[1][1]%m;
long long z = F[1][0]%m * M[0][0]%m + F[1][1] * M[1][0]%m;
long long w = F[1][0]%m * M[0][1]%m + F[1][1] * M[1][1]%m;
F[0][0] = x%m;
F[0][1] = y%m;
F[1][0] = z%m;
F[1][1] = w%m;
}
power(F, n / 2);
multiply(F, F);
if (n % 2 != 0)
multiply(F, M);
}
// Driver program
int main()
{
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << countWays(n) << endl;
}
return 0;
}
15,DBS0009
#include <bits/stdc++.h>
#define Mod 1000000007
#define ll long long
using namespace std;
map<ll, ll> m;
ll fibo(ll n)
{
if (m.count(n))
return m[n];
ll tmp = n / 2;
if (!(n & 1))
{
return m[n] = (fibo(tmp) * fibo(tmp) + fibo(tmp - 1) * fibo(tmp - 1)) %
Mod;
}
return m[n] = (fibo(tmp) * fibo(tmp + 1) + fibo(tmp - 1) * fibo(tmp)) % Mod;
}
void solve()
{
ll n;
cin >> n;
cout << (n == 0 ? 0 : fibo(n - 1)) << endl;
}
int main()
{
m[0] = m[1] = 1;
int test = 1;
cin >> test;
// clean();
while (test--)
{
solve();
}
// pause();
return 0;
}
16,BIN2DC
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while (t--){
string s;
cin >> s;
cout << he_co_so_10(s) << endl;
}
return 0;
}
17,UOCSO006
#include <bits/stdc++.h>
using namespace std;
#include<iostream>
#include<math.h>
using namespace std;
// Kiem tra so nguyen to
int snt(int a)
{
if(a == 0 || a == 1)
{
return 0;
}
for(int i = 2; i <= sqrt(a); i ++)
{
if(a % i == 0)
{
return 0;
}
}
return 1;
}
// Tat ca phan tu deu la so nguyen to
int allsnt(int a)
{
int count;
int dem1 = 0, dem2 = 0; //dem1 dem so luong so, dem2 dem so luong so la snt
while (a > 0)
{
count = a % 10;
if(snt(count) == 1)
{
dem2 ++;
}
a /= 10;
dem1 ++;
}
if(dem1 == dem2)
{
return 1;
}
return 0;
}
//So luong snt nho hon n
void sl(int n)
{
int count = 0;
for(int i = 2; i <= n; i ++)
{
if(allsnt(i) == 1 && snt(i) == 1)
{
count ++;
}
}
cout << count << endl;
}
int main()
{
int test,n;
cin >> test;
while(test --)
{
cin >> n;
sl(n);
}
return 0;
}
19.KTLDT010
#include <iostream>
int main() {
int T;
cin >> T;
while (T--) {
long long N;
cin >> N;
return 0;
}
20,DEC2HEC
#include <bits/stdc++.h>
using namespace std;
void chuyen_sang_Hexa(long long n){
char hexaDecinum[500];
long long i = 0;
if (n == 0) cout << "0" << endl;
else{
while (n != 0){
long long temp = 0;
temp = n%16;
if (temp < 10){
hexaDecinum[i] = temp +48;
i++;
}
else{
hexaDecinum[i] = temp + 55;
i++;
}
n = n/16;
}
for (long long j = i-1; j >= 0; j--){
cout << hexaDecinum[j];
}
cout << endl;
}
}
int main(){
int t;
cin >> t;
while (t--){
long long n;
cin >> n;
chuyen_sang_Hexa(n);
}
return 0;
}
21,DAYSO010
#include<bits/stdc++.h>
using namespace std;
return 0;
}
22,KLDT001
#include <iostream>
using namespace std;
while (i * (i + 1) / 2 < n) {
long long remainder = n - i * (i + 1) / 2;
if (remainder % (i + 1) == 0) {
count++;
}
i++;
}
return count;
}
int main() {
int T;
cin >> T;
while (T--) {
long long N;
cin >> N;
long long ways = countWays(N);
cout << ways << endl;
}
return 0;
}