text
stringlengths
49
983k
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cmath> #include <math.h> #include <vector> #include <algorithm> #include <stack> #include <set> #include <ctime> #include <queue> #include <deque> #include <unordered_set> #include <unordered_map> #include <map> #include <random> #include <cstdio> #include <string> #include <numeric> #include <cctype> #include <cassert> #define double long double //#define int long long #define eb emplace_back #define rs resize #define ld long double #define vi vector<int> #define vpii vector<pair<int, int>> #define ull unsigned long long using namespace std; // typedef long long ll; // typedef vector<int> vi; // typedef long double ld; /*#pragma GCC optimize("Ofast") #pragma GCC optimize("vpt") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("shrink-wrap-separate") #pragma GCC optimize("loop-nest-optimize") */ int gcd(int a, int b) { if (!a)return b; return gcd(b % a, a); } int lcm(int a, int b) { return a * b / gcd(a, b); } void solve() { int n, m; cin >> n >> m; int lc = 1; gcd(3, 2); for (int i = 2; i <= 16; i++) { lc = lcm(lc, i); } vector<vi> a(n, vi(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } vector<vi> b(n, vi(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i + j) % 2 == 0) { cout << lc << ' '; } else { cout << lc + (int)(pow(a[i][j], 4)) << ' '; } } cout << "\n"; } } signed main() { // freopen("‪", "r", stdin); //freopen("C:\\Users\\Asus\\Desktop\\input.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed; cout.precision(30); int t = 1; //cin >> t; while (t--) solve(); // system("pause"); }
#include<bits/stdc++.h> using namespace std; #define ll long long int ll vec[509][509]; int main() { ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p; cin>>n>>m; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>vec[i][j]; if((i+j)%2) { vec[i][j]=720720; } else { vec[i][j]=720720+powl(vec[i][j],4); } } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { printf("%lld ",vec[i][j]); } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; #define fix(f,n) std::fixed<<std::setprecision(n)<<f #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef long long int ll; typedef unsigned long long int ull; #define vi vector<int> #define pii pair<int,int> #define vii vector<pii> #define max(a,b) ((a>b)?a:b) #define min(a,b) ((a>b)?b:a) #define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c) #define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c) #define REP(i,a,n) for(ll i=a;i<n;i++) #define pb push_back #define mp make_pair #define mod 1000000007 #define MAX 1000000001 ll arr[200001],dp[200001]={},par[200001]; void dfs(int u,int parent,vector<vector<int>> &g,int lvl,vector<vector<int>> &nodes){ par[u]=parent; nodes[lvl].pb(u); for(auto i:g[u]){ if(i==parent){ continue; } dfs(i,u,g,lvl+1,nodes); } } int main(){ fast; int test=1; //cin >> test; while(test--){ int n,m; cin >> n >> m; for(int i=0 ; i<n ; i++){ for(int j=0 ; j<m ; j++){ int x; cin >> x; if((i%2)==(j%2)){ cout << 720720+(x*x*x*x) << " "; }else{ cout << 720720 << " "; } } cout << endl; } } return 0; }
#include <bits/stdc++.h> template <class T> inline void read(T &res) { res = 0; bool bo = 0; char c; while (((c = getchar()) < '0' || c > '9') && c != '-'); if (c == '-') bo = 1; else res = c - 48; while ((c = getchar()) >= '0' && c <= '9') res = (res << 3) + (res << 1) + (c - 48); if (bo) res = ~res + 1; } const int N = 505; int n, m, a[N][N]; int main() { read(n); read(m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) read(a[i][j]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) printf("%d ", i + j & 1 ? 720720 : 720720 - a[i][j] * a[i][j] * a[i][j] * a[i][j]); puts(""); } return 0; }
/* * created: 2021-02-12 16:42:12 **/ #include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define x first #define y second using namespace std; template<typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S> &p) { return os << "(" << p.x << ", " << p.y << ")"; } template <class Ch, class Tr, class Container> basic_ostream <Ch, Tr> &operator << (basic_ostream <Ch, Tr> & os, Container const& x) { os << "{"; string sep; for(auto& y : x) os << sep << y, sep = ", "; return os << "}"; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1e9 + 7, N = 550; int n, m; ll gcd(ll a, ll b) { return b ? a : gcd(a % b, b); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } int g[N][N]; void solve() { ll ans = 1; for(int i = 1; i <= 16; i ++) ans = lcm(ans, i); cin >> n >> m; for(int i = 0; i < n; i ++) for(int j = 0; j < m; j ++) { cin >> g[i][j]; } for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { if((i + j) % 2 == 0) cout << ans << ' '; else cout << ans + pow(g[i][j], 4) << ' '; } cout << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE const string filename = "cin"; freopen((filename + ".in").c_str(), "r", stdin); #endif int t; // cin >> t; t = 1; while(t --) { solve(); } return 0; }
//#pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define inf 0x3f3f3f3f #define INF 0x7fffffff #define infll 0x3f3f3f3f3f3f3f3f #define il inline #define re register #define pb push_back #define db double #define ll long long #define ull unsigned long long #define pii pair<int,int> #define pll pair<ll,ll> #define puu pair<ull,ull> #define MP make_pair #define lowbit(x) x&(-x) #define fi first #define se second il ll read() { char ch = getchar(); ll p = 1,data = 0; while(ch<'0'||ch>'9') { if(ch == '-')p = -1; ch = getchar(); } while(ch>='0'&&ch<='9') { data = data*10+(ch^48); ch = getchar(); } return p*data; } il ll gcd(ll a,ll b) { if(!a || !b) return (!a)?b:a; while(b ^= a ^= b ^= a %= b); return a; } il ll lcm(ll a,ll b) { return a*b/gcd(a,b); } void exgcd(ll a, ll b, ll &x,ll &y) { if(!b) x = 1, y = 0; else { exgcd(b, a % b, y, x); y -= x * (a / b); } } il ll qpow(ll a,ll b) { ll r = 1; while(b) { if(b&1)r = a*r; a = a*a; b>>=1; } return r; } const int mod = 1e9+7,maxn = 505; int mp[maxn][maxn],b = 720720; int main() { int n = read(),m = read(); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) mp[i][j] = read(); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) printf("%d%s",b+((i+j)%2?qpow(mp[i][j],4):0),j==m?"\n":" "); return 0; } /* */
#include <bits/stdc++.h> using namespace std; int gcd(int a,int b){ return a%b==0?b:gcd(b,a%b); } int lcm(int a,int b){ return a*b/gcd(a,b); } int main(){ int n,m; cin >> n >> m; int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j]; int l = 1; for(int i=1;i<=16;i++){ l = lcm(l,i); } int b[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if((i+j)%2==0){ b[i][j] = l; }else{ b[i][j] = l + (a[i][j]*a[i][j]*a[i][j]*a[i][j]); // 16^4 + lcm(1,2,3,...,15,16) <= 10^16 } } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cout << b[i][j] << " "; } cout << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; const int lcm=720720; int b[502][502]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { b[i][j]=lcm; int tmp; cin>>tmp; if(b[i-1][j]==lcm||b[i][j-1]==lcm||b[i+1][j]==lcm||b[i][j+1]==lcm) { b[i][j]-=pow(tmp,4); } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cout<<b[i][j]<<" "; } cout<<endl; } }
#include <stdio.h> int a[501][501]; int b[501][501]; int gcd(int a, int b) {//a<b if (a > b) a ^= b ^= a ^= b; if (a == 0) return b; return gcd(b%a, a); } int main() { int i, j, n, m; int tgt[17] = { 0 }; for (scanf("%d%d", &n, &m), i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) scanf("%d",a[i]+j); int lcm = 2; for (i = 3; i <= 16; ++i) lcm = lcm * i / gcd(lcm,i); tgt[1] = lcm - 1; for (int i = 1; i <= 32; ++i) { int d = i * i*i*i; int x = lcm - d; if (x > 0) { for (j = 2; j <= 16; ++j) if (x%j == 0) tgt[j] = x; } x = lcm + d; if (x <= 1000000) { for (j = 2; j <= 16; ++j) if (x%j == 0) tgt[j] = x; } } for (i = 1; i <= n; ++i) { for (j = 1; j <= m; ++j) { if ((i + j) & 1) printf("%d ",lcm); else printf("%d ",tgt[a[i][j]]); } puts(""); } return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair <int, int>; using pll = pair <ll, ll>; #define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL); int main() { FIO(); ll x = 720720; int n, m; cin >> n >> m; ll a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ll last = a[i][j]; a[i][j] = x; if ((i + j) % 2) { for (ll k = 1; k <= 20; k++) { if ((x + (k * k * k * k)) % last == 0) { a[i][j] += (k * k * k * k); break; } } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << a[i][j] << " "; } cout << '\n'; } }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // bool xd=any_of(a.begin(),a.end(),[&](int x){return x==9;}); // all_of, none_of // int cnt=count(a.begin(),a.end(),x); // bool found=binary_search(a.begin(),a.end(),x); true if x in sorted array // int xd=*max_element(a.begin(),a.end()); // min_element typedef long long ll; typedef long double ld; int main(){ cin.tie(0);ios::sync_with_stdio(0); int n,m;cin>>n>>m; for(int i=0;i<n;++i,cout<<endl) for(int j=0;j<m;++j){ int x;cin>>x; cout<<720720+((i+j)%2?x*x*x*x:0)<<" "; } }
#include <bits/stdc++.h> using namespace std; #define ll unsigned long long int main() { int n, m; cin>>n>>m; vector<vector<ll>> a(n, vector<ll> (m)), b(n, vector<ll> (m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin>>a[i][j]; ll lcm = 720720; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if((i + j) % 2) b[i][j] = lcm; else b[i][j] = lcm + pow(a[i][j], 4); } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cout << b[i][j] << " "; } cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 16 + 10; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for (int i = 1; i <= 16; ++i) { for (int j = 1; ; ++j) { int x = i * j; int y = 720720 - x; int z = pow(y, .25); if (z * z * z * z == y && z >= 1) { // cout << i << '\t' << x << '\t' << y << '\t' << z << endl; a[i] = x; break; } } } int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { int x; cin >> x; cout << ((i + j) % 2 ? 720720 : a[x]) << ' '; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin >>n>>m; vector <vector <int> > a(n,vector <int> (m)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin >>a[i][j]; if((i+j)%2==0)a[i][j]=720720; else a[i][j]=a[i][j]*a[i][j]*a[i][j]*a[i][j]+720720; } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cout <<a[i][j]<<" "; }cout <<endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define forq(i , a , b) for (int i = (a); i <= (b); ++i) #define qrof(i , b , a) for (int i = (a); i >= (b); --i) #define forr(i , b) forq( i , 0 , b - 1 ) #define F first #define S second #define IF ->first #define IS ->second #define endl '\n' #define qqmemset(array , val) memset (array , val , sizeof(array)) #define ALLV(vect) vect.begin() , vect.end() #define mid (st + en) / 2 #define mid1 (2 * st + en) / 3 #define mid2 (2 * en + st) / 3 #define lef 2 * Node #define rig lef + 1 mt19937 rng( chrono::steady_clock::now().time_since_epoch().count() ); #define Ran(a, b) rng() % ( (b) - (a) + 1 ) + (a) ll R = 7 + 1e9 , R1 = 19491001 , R2 = 236 , NUMTESTCASE ; const ll NN = 10 + 1e6 ; const double pi = acos(-1.0) ; int di [8] = {1 , 0 , -1 , 0 , 1 , -1 , 1 , -1 } , dj [8] = {0 , 1 , 0 , -1 , 1 , -1 , -1 , 1 } ; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) ; int n , m , x ; cin >> n >> m ; forq (i , 1 , n) { forq (j , 1 , m) { cin >> x ; cout << 720720 + ((i + j) % 2) * x * x * x * x << " " ; } cout << endl ; } return 0; }
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<vector> using namespace std; typedef long long LL; const int N=505; int n,m; int a[N][N]; int b[N][N]; int d[N]; bool in[1000005]; int main() { memset(in,false,sizeof(in)); for (int u=1;u<=16;u++) { d[u]=u*u*u*u; in[d[u]]=true; } scanf("%d%d",&n,&m); for (int u=1;u<=n;u++) for (int i=1;i<=m;i++) scanf("%d",&a[u][i]); for (int u=1;u<=n;u++) { for (int i=1;i<=m;i++) { if ((u+i)&1) printf("720720 "); else printf("%d ",720720-d[a[u][i]]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define sc scanf #define pr printf #define ls rt<<1 #define rs rt<<1|1 typedef long long ll; typedef double db; const ll inf=1ll<<58; const int N=1e3+10; const int mod=1e9+7; typedef pair<int,int> pii; int a[N][N],b[N][N]; void solve(){ int n,m; sc("%d%d",&n,&m); for(int i=1;i<=n;++i) for(int j=1;j<=m;++j){ sc("%d",&a[i][j]); if((i+j)&1) b[i][j]=720720; else b[i][j]=720720+a[i][j]*a[i][j]*a[i][j]*a[i][j]; pr("%d%c",b[i][j]," \n"[j==m]); } } signed main() { int T; // sc("%d",&T); T=1; while(T--)solve(); return 0; }
#include <iostream> #include <vector> #include <chrono> #include <random> #include <cassert> std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); long long L = 1; for(int i = 1; i <= 16; i++) { L = lcm(i, L); } std::vector<long long> val(17, 0); for(int i = 1; i <= 16; i++) { int j = 0; int k = 1; while(1) { j += i; while(k * k * k * k < j) k++; if(k * k * k * k == j) break; } val[i] = L + j; //std::cout << val[i] << '\n'; } int n, m; std::cin >> n >> m; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { int x; std::cin >> x; std::cout << ((i + j) % 2 == 0 ? L : val[x]) << (j + 1 == m ? '\n' : ' '); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef double db; #define all(x) (x).begin(), (x).end() const ll MAXN = 1e9, MINN = -1e9; const ld pi = 3.14159265358979323846264338327950288; const ll lcm_16 = 720720; void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; } void solve() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ll x; cin >> x; if ((i + j) % 2) { cout << lcm_16 << " "; } else { cout << lcm_16 + x * x * x * x << " "; } } cout << "\n"; } } int main() { ll t = 1; fastio(); // cin >> t; while (t--) { solve(); } return 0; }
#include <vector> #include <string> #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #define LL long long using namespace std; inline LL rin() { LL s=0; bool bj=false; char c=getchar(); for(;(c>'9'||c<'0')&&c!='-';c=getchar()); if(c=='-')bj=true,c=getchar(); for(;c>='0'&&c<='9';c=getchar())s=(s<<1)+(s<<3)+(c^'0'); if(bj)return -s; return s; } inline int min(int x,int y){return x<y?x:y;} inline int max(int x,int y){return x>y?x:y;} inline LL min(LL x,LL y){return x<y?x:y;} inline LL max(LL x,LL y){return x>y?x:y;} inline void jh(int &x,int &y){if(x!=y)x^=y^=x^=y;return;} inline void jh(LL &x,LL &y){if(x!=y)x^=y^=x^=y;return;} inline int Gcd(int x,int y){return (!y)?(x):(Gcd(y,x%y));} inline int Lcm(int x,int y){return x/Gcd(x,y)*y;} const int N=5e2+3; int n,m; int L=1; int a[N][N]; inline void work() { n=rin();m=rin(); for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=rin(); for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){int x=a[i][j];if((i+j)&1)printf("%d ",L);else printf("%d ",L+x*x*x*x);}printf("\n");} return; } int main() { for(int i=1;i<=16;i++)L=Lcm(L,i); work(); return 0; }
#include <bits/stdc++.h> #define M 1000000007 #define MOD 1003 #define MD 1337 #define MAXN 200005 #define F first #define S second #define int int64_t #define filler(arr, n) \ for (int i = 0; i < n; i++) \ cin >> arr[i]; using namespace std; vector<vector<int>> directions { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } }; void solve(); int32_t main() { int T = 1; // cin >> T; while (T--) { solve(); } return 0; } /* pre processing binary search target sum dp pattern */ void solve() { int n, m; cin >> n >> m; vector<vector<int>> arr(n, vector<int>(m, 0)), ans(n, vector<int>(m, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i + j) % 2 == 0) { cout << 720720 << " "; } else { cout << 720720 + (int)pow(arr[i][j], 4) << " "; } } cout << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define sz size() #define ff first #define ss second #define mod 1000000007 #define pie 3.14159265359 #define minheap priority_queue<int , vector<int> , greater<int> > #define maxheap priority_queue<int> #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ; ll gcd(ll a, ll b) { if(b==0) return a; else return gcd(b,a%b); } int main() { fast; ll t; t=1; while(t--) { ll n,m,i,j; cin>>n>>m; ll g=1; for(i=1;i<17;i++) { g=g*i/gcd(g,i); } for(i=0;i<n;i++) { for(j=0;j<m;j++) { ll x; cin>>x; if((i+j)%2==0) { cout<<g<<" "; } else { cout<<g+x*x*x*x<<' '; } } cout<<"\n"; } } }
#include<bits/stdc++.h> #define ls(p) p<<1 #define rs(p) p<<1|1 #define de(x) cout<<#x<<" = "<<x<<endl; #define rep(i,a,b) for(int i = (a);i<=(b);++i) #define endl '\n' #define PI acos(-1.0) #define pb push_back using namespace std; void debug(){freopen("data.in","r",stdin);freopen("data.out","w",stdout);} typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e6+10; const int INF = 1e6; const int val = 720720; int n,m; int a[501][501]; int main(){ scanf("%d%d",&n,&m); rep(i,1,n)rep(j,1,m){ int v; scanf("%d",&v); if((i + j)&1) a[i][j] = val + v*v*v*v; else a[i][j] = val; } rep(i,1,n)rep(j,1,m) printf("%d%c",a[i][j],j==m?'\n':' '); return 0; } //720720
#include <bits/stdc++.h> #define ft first #define sd second #define ll long long #ifdef LOCAL #include "debughead.h" #else #define dbg(...) 0 #endif #define sz(x) (x).size() using namespace std; int n, m; int a[505][505]; int b[505][505]; set <int> s1, s2; int gcd(int a, int b) { if(a == 0) return b; return gcd(b % a, a); } bool vis[100]; void solve() { cin >> n >> m; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> a[i][j]; } } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(i % 2 == j % 2) { cout << 720720 - a[i][j]*a[i][j]*a[i][j]*a[i][j] << " "; } else { cout << 720720 << " "; } } cout << "\n"; } } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); #endif // LOCAL int t = 1; // cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++, puts("")) for (int j = 1; j <= m; j++) { int a; scanf("%d", &a); if ((i + j) & 1) printf("%d ", 720720 - a * a * a * a); else printf("720720 "); } return 0; }
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++) #define REP(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++) #define RFOR(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--) #define RREP(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--) typedef long long LL; int main() { int n,m; scanf("%d%d",&n,&m); REP(i,1,n) { REP(j,1,m) { int x; scanf("%d",&x); if((i^j)&1) printf("720720 "); else printf("%d\n",720720-x*x*x*x); } printf("\n"); } return 0; }
#include <iostream> #include <vector> #include <iomanip> #include <algorithm> #include <cmath> #include <queue> #include <set> #include <map> using namespace std; #define debug(x) cout << #x << " is " << x << '\n'; #define ld long double #define int long long const int mod = 1e9; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0, x; j < m; ++j) { cin >> x; cout << 720720 + ((i + j) & 1 ? 0 : x * x * x * x) << ' '; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); set<int> s; for(int i=1;i<=100;i++) s.insert(i*i*i*i); const int N=720720; vector<int> opt(17,0); for(int i=1;i<=16;i++) { for(int j=i;j<=N;j+=i) if(s.find(N-j)!=s.end()) opt[i]=j; assert(opt[i]!=0); } int n,m; cin >> n >> m; vector<vector<int>> a(n+1,vector<int>(m+1,0)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >> a[i][j]; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(((i+j)%2)==0) cout << N << " \n"[j==m]; else cout << opt[a[i][j]] << " \n"[j==m]; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n,m; int** a; int main() { scanf("%d",&n); scanf("%d",&m); a=new int*[n]; for(int i=0;i<n;i++){ a[i]=new int[m]; } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ scanf("%d",&a[i][j]); } } int k=720720; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ int c=(i+j)%2; if(c==0){ cout<<k<<' '; } else{ int p=k+a[i][j]*a[i][j]*a[i][j]*a[i][j]; cout<<p<<' '; } } cout<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=720720; const int X=1e3; int p[X][X],anser[X][X]; int main() { int n,m; cin>>n>>m; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { cin>>p[i][j]; } } for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if((i+j)%2==0) cout<<N+(p[i][j]*p[i][j]*p[i][j]*p[i][j])<<" "; else cout<<N<<" "; } cout<<endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define For(i,x,y) for(ll i=(x);i<=(y);++i) #define FOr(i,x,y) for(ll i=(x);i>=(y);--i) #define rep(i,x,y) for(ll i=(x);i<(y);++i) #define clr(a,v) memset(a,v,sizeof(a)) #define cpy(a,b) memcpy(a,b,sizeof(a)) #define fi first #define se second #define pb push_back #define mk make_pair #define pa pair<ll,ll> #define y1 y11111111111111 #define debug puts("@@@@@@@@@@@@@@@@@@@@@@@") ll read(){ ll x=0,f=1; char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1; for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; return x*f; } void write(ll x){ if (x<0) putchar('-'),write(-x); else{ if (x>=10) write(x/10); putchar(x%10+'0'); } } const ll N=300300,mod=1e9+7; ll n,m; int main(){ n=read(); m=read(); ll lcm=360360*2; For(i,1,n){ For(j,1,m){ ll x=read(); write(((i+j)&1)*x*x*x*x+lcm),putchar(' '); } puts(""); } }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define fi first #define se second #define ll long long #define all(v) (v).begin(), (v).end() using vi = vector<int>; using ii = pair<int, int>; using ld = long double; //BEGIN-LIB: //END-LIB: const int X = 720720; int main () { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; if (i + j & 1) { x *= x; x *= x; cout << X + x << ' '; } else { cout << X << ' '; } } cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; const ll INF = 2e18; ll mat[600][600], ans[600][600]; int main() { FAST; ll n, m, i, j; cin >> n >> m; for(i = 0; i < n; i++) { for(j = 0; j < m; j++) { cin >> mat[i][j]; } } ll special = 720720; int ok = 1; for(i = 0; i < n; i++) { for(j = 0; j < m; j++) { if(j % 2 == ok % 2) { ans[i][j] = special; } else { ans[i][j] = special - (mat[i][j]*mat[i][j]*mat[i][j]*mat[i][j]); } } ok++; } for(i = 0; i < n; i++) { for(j = 0; j < m; j++) { cout << ans[i][j] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> #define ll long long #define INF 1000000 #define MAXN 505 #define Pii pair<ll,ll> #define pb push_back using namespace std; ll n,m,a[MAXN][MAXN],b[MAXN][MAXN],d[20]; vector<ll> A; ll UCLN(ll a, ll b){ if(a==b) return a; if(a>b) UCLN(a-b,b); else UCLN(a,b-a); } ll BCNN(ll a, ll b){ return (a*b/UCLN(a,b) ); } ll BCNN_Mang(){ ll temp = BCNN(A[0], A[1] ); for(ll i=2;i<A.size();i++){ temp = BCNN(temp, A[i]); } return temp; } int main() { //ifstream cin("Multiples&PowerDifferences.inp"); //ofstream cout("Multiples&PowerDifferences.out"); cin >> n >> m; for(ll i=1; i<=n; i++){ for(ll j=1; j<=m; j++){ cin >> a[i][j]; if(d[a[i][j]]==0){ d[a[i][j]]=1; A.pb(a[i][j]); } } } ll U; if(A.size()==1) U=A[0]; else U=BCNN_Mang(); for(ll i=1; i<=n; i++){ for(ll j=1; j<=m; j++){ if(i%2==1){ if(j%2==1) b[i][j]=U; } else if(i%2==0){ if(j%2==0) b[i][j]=U; } } } for(ll i=1; i<=n; i++){ for(ll j=1; j<=m; j++){ if(b[i][j]==U) continue; for(ll k=1; k<=30; k++){ ll x=k*k*k*k; bool check=false; ll x1=U+x; if(x1<=INF){ if(x1%a[i][j]==0){ b[i][j]=x1; check=true; } } if(check) break; ll x2=U-x; if(x2>=1){ if(x2%a[i][j]==0){ b[i][j]=x2; check=true; } } if(check) break; } } } for(ll i=1; i<=n; i++){ for(ll j=1; j<=m; j++){ cout << b[i][j] << ' '; } cout << '\n'; } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <queue> #include <cmath> #include <algorithm> #define ll long long #define rep(i, a, b) for (int i = a; i <= (int)b; i ++) #define per(i, a, b) for (int i = (int)a; i >= b; i --) using namespace std; int n, m; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int tmp = 2; rep(i, 3, 16) tmp = i / gcd(tmp, i) * tmp; scanf("%d %d", &n, &m); rep(i, 1, n) rep(j, 1, m) { int x; scanf("%d", &x); if((i + j) % 2) x = tmp + x * x * x * x; else x = tmp; printf("%d%c", x, " \n"[j == m]); } return 0; }
#include<bits/stdc++.h> using namespace std; int n,m; int main(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++,puts(""))for(int j=0;j<m;j++){ int x;scanf("%d",&x); if((i+j)&1)printf("720720 "); else printf("%d ",720720-x*x*x*x); } return 0; }
#include <stdio.h> #define A 720720 int main() { int n, m, i, j; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { int a; scanf("%d", &a); printf("%d ", (i + j) % 2 == 0 ? A : A - a * a * a * a); } printf("\n"); } return 0; }
#include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<queue> #include<stack> #include <math.h> #include<climits> //#include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define deb(x) cout<<x<<"\n"; #define deB(x,y) cout<<x<<" "<<y<<"\n"; #define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"; #define YES cout<<"YES\n"; #define Yes cout<<"Yes\n"; #define NO cout<<"NO\n"; #define No cout<<"No\n"; #define clt(x) 63-__builtin_clzll(x) #define bct(x) __builtin_popcountll(x) #define all(v) (v).begin(),(v).end() #define pi pair<ll,ll> #define vi vector<ll> #define vpi vector<pair<ll,ll>> #define maxq priority_queue<ll> #define minq priority_queue<ll,vector<ll>, greater<ll>> #define cont continue; #define reto return 0; #define sz size() #define spmod 1116295198451 #define mod 1000000007 #define md 998244353 #define N 200009 //typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds; ll a[509][509]; int 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 ll n,m; cin>>n>>m; ll i=0,j; while(i<n) { j=0; while(j<m) { cin>>a[i][j]; j++; } i++; } i=0; while(i<n) { j=0; while(j<m) { if((i+j)%2) cout<<720720-a[i][j]*a[i][j]*a[i][j]*a[i][j]<<" "; else cout<<"720720 "; j++; } cout<<"\n"; i++; } }
#include<bits/stdc++.h> using namespace std; int main() { int n,m,x; scanf("%d%d",&n,&m); int k=16*9*5*7*11*13; for(int i=1;i<=n;++i) { for(int j=1;j<=m;++j) { scanf("%d",&x); if((i+j)%2==0) printf("%d ",k); else printf("%d ",k-x*x*x*x); } printf("\n"); } return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> #define INF 1000000000 #define LINF 1000000000000000000 #define MOD 1000000007 #define mod 998244353 #define INF63 1061109567 #define INF127 9187201950435737471 #define UINF 18446744073709551615 #define F first #define S second #define ll long long #define N 510 using namespace std; ll n,m,a[N][N],num[20]; int main(){ ll i,j; scanf("%lld%lld",&n,&m); for(i=0;i<20;i++) { num[i]=16*9*5*7*11*13-i*i*i*i; } for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%lld",&a[i][j]); if(i%2!=j%2) { a[i][j]=0; } } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf("%lld ",num[a[i][j]]); } puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, a; cin >> n >> m; int res[n + 1][m + 1]; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> a; res[i][j] = 720720; if((i + j) % 2) res[i][j] += a * a * a * a; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cout << res[i][j] << " "; } cout << endl; } return 0; }
#include<bits/stdc++.h> #include<iostream> using namespace std; #define fastio ios_base::sync_with_stdio(0);cin.tie(0) #define FOR(i,m,n) for(int i = (m); i < (n); i++) #define pb push_back #define mp make_pair #define fst first #define snd second #define all(v) sort(v.begin(),v.end()) #define sz(v) int(v.size()) const int MOD=1e9+7; const int mod= 998244353; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll,ll> ii; int main() { int n,m; cin>>n>>m; int a[700][700]; FOR(i,0,n){ FOR(j,0,m){ cin>>a[i][j]; } } int b[700][700]; FOR(i,0,n){ FOR(j,0,m){ if((i+j)%2){ b[i][j]=720720+a[i][j]*a[i][j]*a[i][j]*a[i][j]; } else b[i][j]=720720; } } FOR(i,0,n){ FOR(j,0,m){ cout<<b[i][j]<<" "; } cout<<endl; } return 0; }
#include <iostream> #include<map> #include<vector> #include<climits> #include<queue> #include<cmath> #include<stack> #include<string> #include<algorithm> #define pb push_back #define N (lli)(3e5) #define lli long long int #define mod (lli)(998244353) #define INF (1e9) #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL) #define pb push_back using namespace std; // Jai Hanuman Gyan Gun Sagar Jai Kapis Ti Log Ujagar int main() { int n,m; cin>>n>>m; vector<vector<int>>arr(n,vector<int>(m)); vector<vector<int>>soln(n,vector<int>(m)); for(int i=0;i<n;i++) for(int j=0;j<m;j++) { cin>>arr[i][j]; if((i+j)%2==0) soln[i][j] = 720720; else soln[i][j] = 720720 + arr[i][j]*arr[i][j]*arr[i][j]*arr[i][j]; } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout<<soln[i][j]<<" "; cout<<endl; } }
#include<bits/stdc++.h> #include<stdlib.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; // cin>>t; while(t--) { long long int n,m,i,j; cin>>n>>m; long long int a[n][m]; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cin>>a[i][j]; } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if((i+j)%2!=0) { a[i][j]=720720+(a[i][j]*a[i][j]*a[i][j]*a[i][j]); } else { a[i][j]=720720; } cout<<a[i][j]<<" "; } cout<<"\n"; } } }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx") #pragma comment(linker, "/STACK:64777216") #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <cstdio> #include <cassert> #include <climits> #include <functional> #include <numeric> #include <algorithm> #include <cmath> #include <ctime> #include <string> #include <cstring> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <list> #include <deque> #include <unordered_set> #include <unordered_map> #include <bitset> #include <array> using namespace std; #define forn(i, n) for(int i = 0; i < int(n); i++) #define forn1(i, n) for(int i = 1; i <= int(n); i++) #define sz(a) int((a).size()) #define all(a) (a).begin(), (a).end() #define mp make_pair #define pb push_back #define x first #define y second typedef long long li; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair <li, li> pt; const int INF = int(1e9); const li INF64 = li(1e18); const ld PI = acosl(ld(-1)); const ld EPS = 1e-9; template <typename T> inline T sqr(const T& x) { return x * x; } template <typename T> inline T abs(const T& x) { return x > 0 ? x : -x; } inline bool inside(int x, int y, int n, int m) { return x >= 1 && x <= n && y >= 1 && y <= m; } inline int rnd() { return abs(rand() ^ (rand() << 15)); } inline int rnd(int n) { assert(n > 0); return rnd() % n; } inline int rnd(int lf, int rg) { return lf + rnd(rg - lf + 1); } inline li rndLL() { return rnd() * 1LL * rnd() + rnd(); } const int dx[4] = { -1, 0, +1, 0 }; const int dy[4] = { 0, +1, 0, -1 }; const int dx8[8] = { -1, -1, 0, +1, +1, +1, 0, -1 }; const int dy8[8] = { 0, +1, +1, +1, 0, -1, -1, -1 }; const int N = int(555); int n, m, a[N][N]; int ans[N][N]; void gen() { } bool read() { if (scanf("%d %d", &n, &m) != 2) return false; forn1(i, n) forn1(j, m) assert(scanf("%d", &a[i][j]) == 1); return true; } int pw4[20]; bool used[int(1e6) + 777]; void solve() { for (li x = 1;; x++) { li y = x* x * x * x; if (y > 1e6) break; //cerr << x << ' ' << y << endl; } /* cerr << "LM == " << 2 * 2 * 2 * 2 * 3 * 3 * 5 * 7 * 11 * 13 << endl; int a = 720720; for (int i = 2; i <= a; i++) { while (a % i == 0) { cerr << i << ' '; a /= i; } } */ int good = 720720; set<int> ss; forn(i, N) forn(j, N) ans[i][j] = good; for (int i = 1; i <= 16; i++) { pw4[i] = i * i * i * i; ss.insert(pw4[i]); used[pw4[i]] = true; } forn1(i, n) { int st = 1; if (i % 2 == 1) st++; for (int j = st; j <= m; j += 2) { int x = a[i][j]; ans[i][j] += pw4[x]; } } /* forn1(i, n) { forn1(j, m) cerr << ans[i][j] << ' '; cerr << endl; } */ forn1(i, n) forn1(j, m) { assert(ans[i][j] <= 1000000); vector<int> difs; if (i - 1 >= 1) difs.push_back(abs(ans[i - 1][j] - ans[i][j])); if (i + 1 <= n) difs.push_back(abs(ans[i + 1][j] - ans[i][j])); if (j - 1 >= 1) difs.push_back(abs(ans[i][j - 1] - ans[i][j])); if (j + 1 <= m) difs.push_back(abs(ans[i][j + 1] - ans[i][j])); forn(k, sz(difs)) { int val = difs[k]; assert(used[val]); } } forn1(i, n) { forn1(j, m) printf("%d ", ans[i][j]); puts(""); } return; } ld gett() { return ld(clock()) / CLOCKS_PER_SEC; } int main() { #ifdef _DEBUG (freopen("input.txt", "rt", stdin)); (freopen("output.txt", "wt", stdout)); #endif cout << setprecision(15) << fixed; cerr << setprecision(15) << fixed; int T = 1; //T = 10000; srand(int(time(NULL))); //gen(); //scanf("%d", &T); //cin >> T; //T = 100; forn(i, T) { #ifdef _DEBUG cerr << "TEST == " << i << endl; #endif //cerr << "TEST == " << i << endl; assert(read()); //cout << "Case #" << i + 1 << ": "; solve(); #ifdef _DEBUG cerr << "curTime == " << clock() << " ms" << endl; #endif //break; } #ifdef _DEBUG cerr << "TIME == " << clock() << " ms" << endl; #endif //cerr << "TIME == " << gett() << " s" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef _FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m; cin >> n >> m; vector<vector<int> > a(n, vector<int>(m)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { int b; cin >> b; if((i + j) % 2 == 0) { a[i][j] = 720720; } else { a[i][j] = b * b * b * b + 720720; } cout << a[i][j] << ' '; } cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; typedef long double ld; const long long inf = 1100000000000000000; #define maxn 1000005 #define mod 1000000007 //998244353 #define int long long #define PB push_back #define eb emplace_back #define all(c) (c).begin(),(c).end() #define pii pair <int,int> #define vi vector<int> #define F first #define S second #define rep(i,a,b) for(int i=a;i<b;i++) #define rep1(i,a,b) for(int i=a;i<=b;i++) #define repd(i,a,b) for(int i=a;i>=b;--i) #define sz(x) (int)((x).size()) #define mem(a,x) memset(a,x,sizeof(a)) const long double PI=3.141592653589793238462643383279502884197169399375105820974944; void solve(){ int n, m; cin>>n>>m; int z = 720720; //lcm{1..16} int a[n][m]; rep(i, 0, n) rep(j, 0, m) cin>>a[i][j]; rep(i, 0, n){ rep(j, 0, m){ int k = z-pow(a[i][j], 4); if((i+j)%2) cout<<z<<" "; else cout<<k<<" "; }cout<<"\n"; } } signed main(){ ios_base::sync_with_stdio(false), cin.tie(nullptr); int T=1;// cin>>T; while(T--){ solve();cout<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, x, y; int gcd(int a, int b){ if (b) return gcd(b, a % b); else return a; } int main() { scanf("%d%d", &n, &m); for (int i=0; i<n; i++){ for (int j=0; j<m; j++) { scanf("%d", &x); if ((i+j)&1) y=720720; else y=720720-x*x*x*x; printf("%d ", y); } printf("\n"); } return 0; }
#include<bits/stdc++.h> using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) typedef long long int ll; typedef long double ld; #define trump(v,a) vector<ll> v(a); for(int i =0;i<a; ++i)cin>>v[i]; #define modi(v) for(auto i:v) cout<<i<<" "; ll p[200005], inv[200005], hell = 998244353 ; ll exp(ll x, ll y) { ll res = 1; x %= hell; while (y) { if (y & 1) res = (res * x) % hell; y >>= 1; x = (x * x) % hell; } return res; } ll bin(ll n, ll r) { if (n < r) return 0; ll res = (p[n] * inv[n - r]) % hell; res = (res * inv[r]) % hell; return res; } bool sortpairs(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } bool isprime(ll a) { for (int i = 2; i * i < a + 1; ++i) { if (a % i == 0) return false; } return true; } // returnd ceil of 2 integers t and a i.e. ceil(t/a) ll ceil(ll t, ll a) { return t / (a ) + 1 * (bool)(t % (a)); } // this returns the smallest element that is closest to the target in the sorted array i.e 9 in [6,9,11] with target 10 ll snear( ll arr[], ll target, ll end) { int start = 0; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to the left side if the target is smaller if (arr[mid] == target) { ans = mid; break; } if (arr[mid] > target) { end = mid - 1; } // Move right side else { ans = mid; start = mid + 1; } } return ans; } // this function returns set of all factors both prime and composite of ll a // to take intersection with another set follow // set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v)); // here v1 v2 are sets and v3 is a vector (or any member with a push_back() function) const vector<ll> allprime(ll a) { vector<ll> v; for (int i = 1; i * i <= a; ++i) { /* code */ if (a % i == 0 ) { v.push_back(i); } } return v; } //this calculates a**b in O(log(n)) called as binary exponenetiation ll bina(ll a, ll b) { ll res = a; ll c = a; ll ans = 1; while (b) { ans = ans % hell; if (b & 1) { ans *= res; } res = (res * res) % hell; b >>= 1; } return ans % hell; } //returns a boolean vector of primes uptill n inclusive of n in o(n*loglogn) const vector<bool> seive(ll n) { std::vector<bool> v(n + 1, true); v[0] = false; v[1] = false; for (ll i = 2; i * i <= n; ++i) { /* code */ if (v[i] ) { for (ll j = i * i; j <= n; j += i ) { /* code */ v[j] = false; } } } return v; } void solve() { ll a = 19, b = 9, c = 0, t = 1, ans = 0, k = 1, ans2 = 10000000000, c1 = 0, c2 = 0, n = 0, m = 0, x = 22311311; cin >> a >> b; c = 720720; k = ll(pow(c, 0.25)); t = c; std::vector<ll> v(17); while (c > 0) { c1 = pow(t - c, 0.25); if ( c1 * c1 * c1 * c1 == t - c ) { for (int i = 1; i <= 16; ++i) { /* code */ if (c % i == 0) { // cout << i << " " << t - c << endl; v[i] = c; } } } c--; } for (int i = 1; i <= a; ++i) { /* code */ for (int j = 1; j <= b; ++j) { /* code */ cin >> x; if ((i + j) % 2 == 0)cout << t << " " ; else cout << v[x] << " "; } cout << endl; } } int 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 clock_t z = clock(); ll qc = 1; // cin >> qc; // p[0] = inv[0] = 1; // for (ll i = 1; i < 200005; i++) { // p[i] = (i * p[i - 1]) % hell; // inv[i] = bina(p[i], hell - 2); // } // seive1(1000000); for (ll i = 1; i <= qc; i++) solve(); debug("Total Time: % .4Lf\n", (ld)(clock() - z) / CLOCKS_PER_SEC); }
// Igorjan94, template version from 13 October 2017. C++17 version, modified 18 march 2020 (writeln<tuple>, whole->all) {{{ #include <bits/stdc++.h> using namespace std; #define FOR(i, m, n) for (int i = m; i < (int) (n); ++i) #define ROF(i, m, n) for (int i = m; i >= (int) (n); --i) #define forn(i, n) for (int i = 0; i < (int) (n); ++i) #define fori1(n) for (int i = 1; i < (int) (n); ++i) #define forj1(n) for (int j = 1; j < (int) (n); ++j) #define fori(n) for (int i = 0; i < (int) (n); ++i) #define forj(n) for (int j = 0; j < (int) (n); ++j) #define SZ(a) int(size(a)) typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; #define pb push_back #define all(a) begin(a), end(a) #define ints(a...) int a; readln(a) [[maybe_unused]] const int MOD = 1000000007; [[maybe_unused]] const int INTMAX = numeric_limits<int>::max(); #define ttt12i template<class T1, class T2> inline #define ttti template<class T> inline void writeln(){cout<<"\n";}ttti void print(T&& a);ttti void priws(T&& a);ttti void read(T& a); template<class... Args> inline void readln(Args&... args){(read(args),...);} template<class H, class...T> inline void writeln(H&& h,T&&...t){priws(h);(print(t),...);writeln();} //Igorjan //}}} void run() { ints(n, m); vector<vi> a(n, vi(m)); vector<vi> b(n, vi(m, 720720)); readln(a); fori(n) forj(m) if ((i + j) % 2 == 0) b[i][j] += a[i][j] * a[i][j] * a[i][j] * a[i][j]; writeln(b); } //{{{ int main() { ios_base::sync_with_stdio(false); run(); cerr << fixed << setprecision(0) << "Execution time = " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } #define a _a #define n _n ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a); template<typename T,typename D=decltype(*begin(declval<T>())),typename enable_if<!is_same<T,basic_string<char>>::value>::type* =nullptr> ostream&operator<<(ostream&os,T const&a){auto it=begin(a);if(it!=end(a))os<<*it++;while(it!=end(a))os<<"\n "[is_fundamental<typename T::value_type>::value]<<*it++;return os;} ttt12i ostream&operator<<(ostream&os,pair<T1,T2>const&a){return os<<a.first<<" "<<a.second;} ttt12i istream&operator>>(istream&is,pair<T1,T2>&a){return is>>a.first>>a.second;} ttti istream&operator>>(istream&is,vector<T>&a){fori(a.size())is>>a[i];return is;} ttti void print(T&&a){cout<<" "<<a;} ttti void priws(T&&a){cout<<a;} ttti void read(T&a){cin>>a;} //}}}
#include <bits/stdc++.h> #include <unordered_map> #include <chrono> #define mp make_pair #define ll long long #define ll_MAX 1e18 using namespace std; vector<int> nums; double quadraticFormula(double a, double b, double c) { pair<double, double> totalResults = mp(-1, -1); double numeratorSqrtResult = sqrt((b * b) - (4 * a * c)); double denominatorResult = 2 * a; double addNegativeTo_b = 0 - b; if (denominatorResult == 0) { cout << 1 / 1; exit(0); } totalResults.first = (addNegativeTo_b + numeratorSqrtResult) / denominatorResult; totalResults.second = (addNegativeTo_b - numeratorSqrtResult) / denominatorResult; return max(totalResults.first, totalResults.second); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; if ((i+j)%2==0) { cout << 720720 << " "; } else { cout << 720720 - pow(x, 4) << " "; } } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define co(n) cout<<n<<endl; const int x=720720; int n,m,k; int main(int argc, char const *argv[]) { scanf("%d %d", &n, &m); for (int i=1;i<=n;++i) { for (int j=1;j<=m;++j) { scanf("%d", &k); if ((i+j)&1) printf("%d ", x); else printf("%d ", x - k*k*k*k); } printf("\n"); } return 0; }
#include<bits/stdc++.h> using namespace std; int a[555][555]; int main() { int n, m; cin >> n >> m; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> a[i][j]; if((i + j) & 1){ a[i][j] = 720720 + pow(a[i][j], 4); } else{ a[i][j] = 720720; } } } for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cout << a[i][j] << ' '; } puts(""); } }
#include<bits/stdc++.h> using namespace std; int main (){ ios::sync_with_stdio(0);cin.tie(0); int n,m; cin>>n>>m; for (int i=0;i<n;i++){ for (int j=0;j<m;j++){ int a; cin>>a; if ((i+j)%2) cout<<"720720 "; else cout<<720720-a*a*a*a<<" "; } cout<<'\n'; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ff first #define ss second #define all(x) (x).begin(), (x).end() const int maxn = 720720; int f(int x){ return x * x * x * x; } void solve(){ int n, m; cin >> n >> m; vector< vector< int > > a(n, vector< int >(m)); for(auto& v : a){ for(auto& u : v) { cin >> u; }} for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ if((i + j) & 1){ cout << maxn << ' '; } else { cout << maxn + f(a[i][j]) << ' '; } } cout << '\n'; } } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++){ // cout << "Case #" << i << ": "; solve(); } return 0; }
#include <bits/stdc++.h> #define taskname "" #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define for0(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef long long ll; typedef long double ld; typedef complex <ld> cd; typedef vector <cd> vcd; typedef vector <int> vi; template<class T> using v2d = vector <vector <T> >; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int maxN = 5e2 + 10; const int maxM = 5e2 + 10; int n, m, a[maxN][maxM], c[17]; ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b, a % b); } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } void solve() { int g = 1; for1(i, 16) { g = LCM(g, i); } vi vec; for1(i, 32) { if (i * i * i * i <= 1e6) { vec.eb(i * i * i * i); } } for1(i, 16) { for (int j = i; j <= 1e6; j += i) { if (binary_search(all(vec), abs(j - g))) { c[i] = j; break; } } } cin >> n >> m; for1(i, n) { for1(j, m) { cin >> a[i][j]; } } for1(i, n) { for1(j, m) { if ((i + j) & 1) { cout << g << " "; } else { cout << c[a[i][j]] << " "; } } cout << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(ll i=(a);i<(b);i++) #define per(i,a,b) for(ll i=(b)-1;i>=(a);i--) using ll=long long; using vi=vector<int>; int get_4th(int x) { return x*x*x*x; } int main(){ ios_base::sync_with_stdio(0); int n,m; cin>>n>>m; vector<vi> a(n,vi(m)); rep(i,0,n) rep(j,0,m) cin>>a[i][j]; int k=16*9*5*7*11*13; rep(i,0,n) { rep(j,0,m) cout<<k+((i+j)&1?get_4th(a[i][j]):0)<<" "; cout<<"\n"; } }
#include<iostream> #include<bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mod 1000000007 #define inarr(i,arr,n); for(ll i=0;i<n;i++) cin >> arr[i]; #define outarr(i,arr,n); for(ll i=0;i<n;i++) cout<<arr[i]<<' '; #define swap(a,b,t) {t=a;a=b;b=t;} #define ve vector #define sz(a) (int)((a).size()) #define fi first #define se second #define pa pair #define all(x) x.begin(), x.end() #define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);} #define fr(i, a, b) for (ll i = a; i <= b; i++) #define frn(i, a, b) for (ll i = a; i >= b; i--) #define mk make_pair #define ceil(x) (ll)(ceil(x)) #define endl "\n" #define setvector(i, vname,value,size); for(ll i=0;i<size;i++)vname[i]=value; const ll inf = 1e18; ll gcd(ll a,ll b) { if(a%b==0) return b; else return gcd(b,a%b); } int main() { fastio ll n, m; cin>>n>>m; ve <ve <ll>> in(n, ve <ll>(m)); fr(i, 0, n-1) { inarr(j, in[i], m); } ll fac16=1; fr(i, 2, 16) { fac16=(fac16*i)/gcd(fac16, i); } //cout<<fac16<<endl; ve <ve <ll>> ans(n, ve <ll>(m, fac16)); fr(i, 0, n-1) { fr(j, 0, m-1) { if((i+j)%2) { ans[i][j]+=pow(in[i][j], 4); } cout<<ans[i][j]<<" "; } cout<<endl; } }
#include <iostream> #include <fstream> #include <vector> #include <string> #include <algorithm> #include <deque> #include <queue> #include <map> #include <set> #include <cmath> #include <ctime> #include <random> using namespace std; void solve() { int n, m; cin>>n>>m; vector < vector < int > > a(n, vector < int > (m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin>>a[i][j]; } } for (int i = 0; i < n; i++, cout<<"\n") { for (int j = 0; j < m; j++) { if ((i + j) % 2 == 0) { cout<<"720720 "; } else { cout<<(720720 + (int)pow(a[i][j], 4))<<" "; } } } } int main() { ios::sync_with_stdio(false); int t = 1; while (t--) solve(); }
//#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; //vector string deque break continue #define forn(i, s, f) for (int i = (int)s; i < (int)f; i++) #define ll long long #define ull unsigned long long #define ld long double #define pii pair <int, int> #define fs first #define sc second #define pf push_front #define pb push_back #define pop_f pop_front #define pop_b pop_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #ifdef DEBUG #else #define cerr if (false) cerr #endif template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;} template <typename T> ostream& operator<<(ostream& out, vector <T>& a) {for (auto& i : a) out << i << " "; return out;} template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;} template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;} constexpr int LCM = 720720; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int> (m)); cin >> a; forn (i, 0, n) { forn (j, 0, m) { if (i + j & 1) cout << LCM; else cout << LCM + a[i][j] * a[i][j] * a[i][j] * a[i][j]; cout << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+10; typedef long long ll; int a[550][550]; int solve(int x){ return x*x*x*x; } int main(){ int n,m,d = 720720; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&a[i][j]); if((i&1)&&(j&1)) a[i][j] = d; else if(!(i&1)&&!(j&1)) a[i][j] = d; else a[i][j] = solve(a[i][j]) + d; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ printf("%d",a[i][j]); if(j==m) printf("\n"); else printf(" "); } } }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll mod=1e9+7; ll mtr[600][600]; ll n,m,k; int main() { int n,m; cin>>n>>m; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>mtr[i][j]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if((i+j)&1) { cout<<720720+mtr[i][j]*mtr[i][j]*mtr[i][j]*mtr[i][j]<<" "; }else cout<<720720<<" "; } cout<<endl; } }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define int long long int #define MOD 998244353 #define pb push_back #define pf push_front #define vi vector<int> #define mi map<int,int> #define umi unordered_map<int,int> #define pii pair<int,int> #define ff first #define ss second #define inf 1e18 #define case int test;cin>>test;while(test--) //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int powm(int x, int y, int m = MOD) { x = x % m; int res = 1; while (y) {if (y & 1)res = res * x; res %= m; y = y >> 1; x = x * x; x %= m;} return res; } int modi(int a, int m = MOD) {return powm(a, m - 2, m);} void pre() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { pre(); //case { int n, m; cin >> n >> m; int a[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; int vl = 720720; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((i + j) % 2 == 0) cout << vl << " "; else { cout << vl + pow(a[i][j], 4) << " "; } } cout << endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define vi vector<int> #define vll vector<ll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define pii pair<int,int> #define pll pair<ll,ll> #define vii vector<pii> #define uset unordered_set #define heap priority_queue #define pb push_back #define mkp make_pair #define ff first #define ss second #define endl "\n" #define all(x) x.begin(),x.end() #define sortall(x) sort(all(x)) #define sortrev(x) sort(all(x), greater<int>()) #define op(x) cout<<x<<endl #define show(x) cout << (#x) << " : " << x << endl #define speedhack ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define YesNo(condition) cout<< (condition ? "Yes" : "No") << "\n" #define YESNO(condition) cout<< (condition ? "YES" : "NO") << "\n" #define MOD 1000000007 #define MAX 200005 void magic(); int main(){ speedhack; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; // cin>>t; while(t--) magic(); return 0; } void magic(){ ll n,m; cin>>n>>m; vvl arr(n,vll(m)); for(ll i=0;i<n;i++){ for(ll j=0;j<m;j++){ cin>>arr[i][j]; if((i+j)%2==0){ arr[i][j] = 720720; }else{ arr[i][j] = 720720 + (arr[i][j]*arr[i][j]*arr[i][j]*arr[i][j]); } cout<<arr[i][j]<<" "; } cout<<endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long int ll vec[509][509]; int main() { ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p; cin>>n>>m; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cin>>vec[i][j]; if((i+j)%2==0) { vec[i][j]=720720; } else { vec[i][j]=720720+powl(vec[i][j],4); } } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { printf("%lld ",vec[i][j]); } printf("\n"); } }
#include <bits/stdc++.h> #define int long long int using namespace std; int a[505][505]; int b[505][505]; int lc = 720720; signed main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n , m; cin>>n>>m; for(int i = 1;i<= n;i++){ for(int j = 1;j<= m;j++){ cin>>a[i][j]; } } for(int i = 1;i<= n;i++){ for(int j = 1;j<= m;j++){ if( (i+j)%2 == 0 ){ b[i][j] = lc; } else{ b[i][j] = lc - a[i][j]*a[i][j]*a[i][j]*a[i][j]; } } } for(int i = 1;i<= n;i++){ for(int j = 1;j<= m;j++){ cout<<b[i][j]<<" "; } cout<<"\n"; } }
/*ॐ नमो भगवते वासुदेवाय नमः*/ #include<bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; const double pi = 3.14159265359; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int binpow(int a, int b, int m) { a %= m; int res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } int inverse(int x){ return binpow(x, MOD - 2, MOD); } void solve() { int n, m, g = 720720; cin >> n >> m; vector<vector<int>> a (n, vector<int> (m)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> a[i][j]; if((i + j) & 1) cout << g << " "; else cout << g - (a[i][j] * a[i][j] * a[i][j] * a[i][j]) << " "; } cout << "\n"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); solve(); cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n "; }
#include <iostream> using namespace std; int main(){ unsigned h,w,x,y,t; cin>>h>>w; for(y=0; y<h; ++y){ for(x=0; x<w; ++x){ cin>>t; if((x^y)&1) cout<<"720720 "; else cout<<720720+t*t*t*t<<' '; } cout<<'\n'; } return 0; }
// coached by rainboy #include <algorithm> #include <iostream> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int a; cin >> a; cout << (i % 2 == j % 2 ? a * a * a * a : 0) + 720720 << ' '; } cout << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc=1; // cin>>tc; while(tc--) { int n,m; cin>>n>>m; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { int x; cin>>x; if((i+j)%2) x=720720+(x*x*x*x); else x=720720; cout<<x<<" "; } cout<<"\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #include <stack> #define ll long long #define ld long double const ll INF=100000000000000000; #define vecpair vector<pair <ll,ll> > #define priqs priority_queue<ll, vector<ll>, greater<ll> > #define priqg priority_queue<ll> #define pb push_back #define mp make_pair #define mt make_tuple #define vel vector<ll> #define endl "\n" #define forl for(int i=0;i<n;i++) const ll MAXN=15000001; bool prime[15000001]; void SieveOfEratosthenes() { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. memset(prime, true, sizeof(prime)); for (int p=2; p*p<=15000000; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] == true) { // Update all multiples of p greater than or // equal to the square of it // numbers which are multiple of p and are // less than p^2 are already been marked. for (int i=p*p; i<=15000000; i += p) prime[i] = false; } } } ll bs(vel &a,ll i,ll j,ll val){ int l=i; int h=j; int m; if(a[h]<val) return -1; while(l<=h){ m=(l+h)/2; if(a[m]>=val) h=m-1; else if(a[m]<val) l=m+1; } if(a[m]<val) m++; return m; } ll bins(vel &a,ll n,ll val){ int l=0; int h=n-1; int m; while(l<=h){ m=(l+h)/2; if(a[m]>val) h=m-1; else if(a[m]<val) l=m+1; else return 1; } return 0; } ll power(ll x, ll y) { ll p=INF; ll res = 1; // Initialize result x = x; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) ; // y must be even now y = y>>1; // y = y/2 x = (x*x); } return res; } ll powermod(ll x, ll y,ll z) { ll p=z; ll res = 1%z; // Initialize result x = x%z; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x)%z ; // y must be even now y = y>>1; // y = y/2 x = (x*x)%z; } return res%z; } ll mex(vel a,int n){ sort(a.begin(),a.end()); int j=a[0]; if(j!=0) return 0; else{ for(int i=1;i<n;i++){ if(a[i]!=a[i-1]){ if(a[i]!=a[i-1]+1){ return j+1; }else j++; } } return j+1; } } int spf[MAXN]; // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) void sieve() { spf[1] = 1; for (int i=2; i<MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i=4; i<MAXN; i+=2) spf[i] = 2; for (int i=3; i*i<MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j=i*i; j<MAXN; j+=i) // marking spf[j] if it is not // previously marked if (spf[j]==j) spf[j] = i; } } } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } void lps(string pat, int M, int* lps) { // length of the previous longest prefix suffix int len = 0; lps[0] = 0; // lps[0] is always 0 // the loop calculates lps[i] for i = 1 to M-1 int i = 1; while (i < M) { if (pat[i] == pat[len]) { len++; lps[i] = len; i++; } else // (pat[i] != pat[len]) { // This is tricky. Consider the example. // AAACAAAA and i = 7. The idea is similar // to search step. if (len != 0) { len = lps[len - 1]; // Also, note that we do not increment // i here } else // if (len == 0) { lps[i] = 0; i++; } } } } ll c(ll m,ll n){ ll ans=1; for(int i=1;i<=n;i++){ ans=(ans*(m-i+1))/i; } return ans; } ll gcdExtended(ll a, ll b, ll* x, ll* y) { // Base Case if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; // To store results of recursive call ll gcd = gcdExtended(b % a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll modInverse(ll a, ll m) { ll x, y; ll g = gcdExtended(a, m, &x, &y); // m is added to handle negative x ll res = (x % m + m) % m; return res; } ll pc(ll n){ for(int i=2;i*i<=n;i++){ if(n%i==0) return 0; } return 1; } ll lexo(string a,string b){ ll n=a.length(); for(int i=0;i<n;i++){ if(a[i]<b[i]) return 1; else if(b[i]<a[i]) return 0; } return 0; } ll mod(ll x){ return (x%INF+INF)%INF; } ll next(ll i,ll n){ if(i<n-1) return i+1; else return 0; } ll nsum(ll n){ return (n*(n+1))/2; } ll chk(ll a,ll b){ if(a==b) return 0; else return 1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll test=1; while(test--){ ll a[17]={}; for(int i=1;i<=16;i++){ ll g=1; while(1){ if((720720-g*g*g*g)%i==0){ a[i]=720720-g*g*g*g; break; } g++; } } ll n,m; cin>>n>>m; ll arr[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>arr[i][j]; } } ll b[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if((i+j)%2==0) b[i][j]=720720; else b[i][j]=a[arr[i][j]]; } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cout<<b[i][j]<<" "; } cout<<endl; } } }
#include <iostream> #include <vector> using namespace std; vector<vector<int>> v; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; v.resize(n, vector<int>(m)); for (auto& x : v) for (auto& y : x) cin >> y; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) v[i][j] = (i + j) & 1 ? 720720 : 720720 + v[i][j] * v[i][j] * v[i][j] * v[i][j]; for (auto& x : v) { for (auto& y : x) cout << y << ' '; cout << '\n'; } cin.ignore(2); return 0; }
// how to come up with these logics :( #include <bits/stdc++.h> using namespace std; #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); } #define pb push_back #define ll long long #define ld long double #define vi vector<int> #define vll vector<long long> #define mp make_pair #define infi INT_MAX #define infl LONG_LONG_MAX #define f(i,a,b) for(ll i=a;i<b;i++) #define ff first #define ss second #define pll pair<ll,ll> #define endl "\n" #define ALL(v) v.begin(),v.end() #define nl cout<<"\n"; int main() { fast ll ntc=1; // cin>>ntc; f(ks,1,ntc+1) { //cout<<"Case #"<<i<<": "; ll n,m; cin>>n>>m; ll a[505][505]; f(i,0,n){ f(j,0,m){ cin>>a[i][j]; ll x = a[i][j]; if((i+j)%2==0) cout<<"720720"<<" "; else cout<<x*x*x*x + 720720<<" "; } cout<<endl; } } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("O4") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("unswitch-loops") #pragma GCC optimize("fast-math") #pragma GCC optimize("tracer") #pragma GCC target("sse2") #pragma GCC target("sse3") #pragma GCC target("popcnt") #pragma GCC target("abm") #pragma GCC target("mmx") #pragma GCC target("tune=native") namespace Competitive { using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define all(a) begin(a), end(a) #define len(a) (int)a.size() #define pb push_back #define eb emplace_back #define em emplace void useiostream() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(20); } void drop(char const *bu) { printf("%s", bu); exit(0); } ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ld const pi = acos(-1.0L); ld const eps = 1e-6; template <typename T, typename TT> bool mi(T &a, TT b) { return a > b ? (a = b, true) : false; } template <typename T, typename TT> bool ma(T &a, TT b) { return a < b ? (a = b, true) : false; } auto seed = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 ran(seed); int Mod[] = {1000000007, 1052339657, 998244353}; int const mod = 1000000007; } // namespace Competitive using namespace Competitive; int n, m; int arr[505][505]; ll lcm(vector<ll> a) { if (len(a) == 2) return lcm(a[0], a[1]); auto t = a.back(); a.pop_back(); return lcm(t, lcm(a)); } int main(int argc, char *args[]) { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); useiostream(); cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; } } vector<ll> a; for (int i = 1; i <= 16; i++) a.pb(i); ll t = lcm(a); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i + j & 1) { cout << t + arr[i][j] * arr[i][j] * arr[i][j] * arr[i][j]; } else { cout << t; } cout << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define vpi vector<pii> #define vpl vector<pll> #define pb push_back #define all(v) v.begin(),v.end() #define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL); void cout_vector(vi v){ for (ll unsigned i=0; i<v.size(); i++) cout << v[i] << " "; cout<<endl; } void cout_vector(vll v){ for (ll unsigned i=0; i<v.size(); i++) cout << v[i] << " "; cout<<endl; } int sum_vector(vi v){ return accumulate(all(v),0); } void sort_vector(vi&v){ sort(all(v)); } void sort_comp(vi &v, bool func(int,int)){ sort(all(v),func); } bool comp(int a,int b){ bool aend=0; if(a%2) a--,aend=1; if(b%2) b--; a/=2; b/=2; if(a==b){ if(aend) return 1; return 0; } if(a<b) return 1; return 0; } ll gcd(ll a, ll b){ a=abs(a); b=abs(b); while(a){ ll temp =a; a=b%a; b=temp; } return abs(b); } ll lcm(ll a, ll b){ return (a*b)/gcd(a,b); } string binary(ll num){ string ans=""; do{ ans=to_string(num%2)+ans; num/=2; }while(num); return ans; } const int mxn = 5e5+2; const int mill = 1e6+3; const ll mod = 1e9+7; ll pwr(ll num, ll p){ ll res=1; while(p>0){ if(p&1) res=(res*num)%mod; num=(num*num)%mod; p/=2; } return res; } ll inverse(ll num){ return pwr(num,mod-2); } void solve(){ int n,m; cin>>n>>m; int num; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>num; if((i+j)%2) cout<<720720<<" "; else cout<<720720+pwr(num,4)<<" "; } cout<<"\n"; } } int main() { fast_io int t; //cin>>t; t=1; while(t--) solve(); return 0; }
#include <bits/stdc++.h> #include <cmath> #include <sstream> #include <vector> #include <stdio.h> #define ll long long #define fr(i,j,p) for(ll i=j; i<p ;i++) #define frr(i,j,p) for(ll i=j; i>=p ;i--) #define PI 3.14159265358979323846 #define print(m) std::cout << std::fixed << std::setprecision(11) << m <<endl; #define mkp make_pair #define pb push_back #define M 32 #define lbindex(a,x) (int)(lower_bound(a.begin(), a.end(),x)-a.begin()); #define upindex(a,x) (int)(upper_bound(a.begin(), a.end(),x)-a.begin()); #define all(a) (a).begin(),(a).end() #define mem(b,a,n) memset(b,a,sizeof(b[0])*n); #define meme(b,a,n,m) memset(b,a,sizeof(b[0][0])*n*m); #define ff first #define ss second #define endl '\n' //ll md=1000000007; //ll mdd=998244353; using namespace std; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef pair<ll, ll> pll; typedef pair<int, int> pii; int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; vvi b(n, vi(m,720720)); fr(i,0,n) { fr(j,0,m) { int x; cin>>x; if((i+j)%2) b[i][j]+=(x*x*x*x); cout<<b[i][j]<<' '; } cout<<endl; } return 0; }
#include<iostream> #include<cstdio> using namespace std; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { int x; scanf("%d",&x); if((i+j)&1) { printf("%d ",720720); } else { printf("%d ",720720+x*x*x*x); } } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int N, M, K; int main(void) { cin >> N >> M >> K; if (K > N) { long long int Sol = 1LL; for (int i = 0; i < N; i++) Sol = (Sol * M) % 1000000007LL; cout << Sol << endl; return 0; } if (K == N) { long long int Sol = 1LL; for (int i = 0; i < (N + 1) / 2; i++) Sol = (Sol * M) % 1000000007LL; cout << Sol << endl; return 0; } if (K == 1) { long long int Sol = 1LL; for (int i = 0; i < N; i++) Sol = (Sol * M) % 1000000007LL; cout << Sol << endl; return 0; } if (K % 2 == 1) { cout << (M * M) % 1000000007LL << endl; return 0; } cout << M << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX_N = 2010; int n, m, k; int visited[MAX_N]; vector<int> graph[MAX_N]; void DFS(int node) { visited[node] = 1; for (size_t i = 0; i < graph[node].size(); ++i) { if (!visited[graph[node][i]]) { DFS(graph[node][i]); } } } int main() { scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= n - k + 1; ++i) { int left = i; int right = i + k - 1; while (left < right) { graph[left].push_back(right); graph[right].push_back(left); ++left; --right; } } int solution = 1; for (int i = 1; i <= n; ++i) { if (!visited[i]) { DFS(i); solution = ((long long)solution * m) % MOD; } } printf("%d\n", solution); return 0; }
#include <bits/stdc++.h> using namespace std; string itos(int x) { stringstream ss; ss << x; return ss.str(); } int n, m, k, a[2010], vis[2010]; set<int> s1; int pwr(int b, int e) { if (e == 0) return 1; if (e == 1) return b; int nxt = (1LL * b * b) % 1000000007; return (1LL * pwr(nxt, e / 2) * pwr(b, e % 2)) % 1000000007; } void dfs(int i) { if (vis[i]) return; vis[i] = 1; for (int r = i; i + k > r && r < n; r++) { int dx = r - i; int l = r - k + 1; if (l < 0) continue; a[l + dx] = a[i] = min(a[l + dx], a[i]); if (not vis[l + dx]) dfs(l + dx); } } int main() { ios_base::sync_with_stdio(false); cin >> n >> m >> k; for (int i = 0; i < n; i++) a[i] = i; for (int i = 0; i < n; i++) dfs(i); for (int i = 0; i < n; i++) s1.insert(a[i]); cout << pwr(m, s1.size()) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int d[2222]; int find(int x) { return x != d[x] ? (d[x] = find(d[x])) : x; } void uu(int x, int y) { x = find(x); y = find(y); if (x != y) d[x] = y; } int main() { int i, j, k, n, m; const int MOD = 1000000007; long long an = 1; scanf("%d%d%d", &n, &m, &k); for (i = 0; i < n; i++) d[i] = i; for (i = 0; i + k <= n; i++) for (j = 0; j < k - 1 - j; j++) uu(d[i + j], d[i + k - 1 - j]); for (i = 0; i < n; i++) if (d[i] == i) an = an * m % MOD; cout << an << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; long long n, m, k; long long temp = 1; int main() { cin >> n >> m >> k; if (k == 1 || k > n) { for (int i = 0; i < n; i++) { temp *= m; temp %= MOD; } cout << temp << endl; return 0; } if (k == n) { for (int i = 0; i < (n + 1) / 2; i++) { temp *= m; temp %= MOD; } cout << temp << endl; return 0; } if (k % 2) cout << m * m << endl; else cout << m << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 310; const int mod = 1e9 + 7; long long Pow(int m, int n) { long long res = 1; for (int i = 0; i < n; i++) res = (res * m) % mod; return res; } int main() { int m, n, k; cin >> m >> n >> k; if (k == 1 || k > m) cout << Pow(n, m); else if (k == m) cout << Pow(n, (k + 1) / 2); else if (!(k % 2)) cout << n; else if (k % 2) cout << (n * n) % mod; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; int main() { int n, m, k, i; cin >> n >> m >> k; long long ans; if (k == 1 || n < k) { ans = 1; for (i = 0; i < n; i++) { ans *= m; ans %= INF; } cout << ans << endl; return 0; } if (k % 2 == 0) { if (n == k) { ans = 1; for (i = 0; i < k / 2; i++) { ans *= m; ans %= INF; } } else ans = m; cout << ans << endl; return 0; } if (k & 1) { if (n == k) { ans = 1; for (i = 0; i < (k / 2 + 1); i++) { ans *= m; ans %= INF; } } else { ans = m * m; } cout << ans << endl; return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 28; const double eps = 1e-8; const int mod = 1e9 + 7; int n, m, k; int quick(int m, int n) { int ans = 1; while (n) { if (n & 1) ans = (1ll * ans * m) % mod; n >>= 1; m = (1ll * m * m) % mod; } return ans; } int main() { while (cin >> n >> m >> k) { if (k > n || k == 1) { cout << quick(m, n) << endl; } else if (k == n) { cout << quick(m, (n + 1) >> 1) << endl; } else { if (k & 1) { cout << (m * 1ll * m) % mod << endl; } else { cout << m % mod << endl; } } } return 0; }
#include <bits/stdc++.h> const int N = 200500; const int Q = 1 << 21; const long long mod = 1e9 + 7; using namespace std; long long n, m, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; if (k == 1 || k > n) { long long ans = 1; for (int i = 0; i < n; i++) ans = ans * m % mod; cout << ans; return 0; } if (k == n) { long long ans = 1; for (int i = 1; i <= (n + 1) / 2; i++) ans = ans * m % mod; cout << ans; return 0; } if (k % 2) { cout << m * m; return 0; } else { cout << m; return 0; } }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int main() { long long n, m, k; scanf("%lld%lld%lld", &n, &m, &k); if (k == 1 || k > n) { long long res = 1; for (int i = 1; i <= n; i++) { res = res * m % mod; } cout << res << '\n'; return 0; } if (k == n) { long long res = 1; for (int i = 0; i < n / 2 + (n % 2); i++) { res = res * m % mod; } cout << res << '\n'; return 0; } if (k % 2 == 0) { cout << m << '\n'; return 0; } long long res = 1; cout << m * m % mod << '\n'; }
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } int mod = 1000000007; int n, m, k, half, i; long long ans; int cb(int n, int k) { int i, ret = 1; for (i = 1; i <= k; ++i) { ret *= n - k + i; ret /= i; } return ret % mod; } int main() { scanf("%d%d%d", &n, &m, &k); if (m == 1) { printf("1\n"); return 0; } if (k == 1) { ans = 1; for (i = 0; i < (n); ++i) { ans *= m; ans %= mod; } cout << ans << endl; return 0; } if (n == k) { half = n / 2; if (n % 2) ++half; ans = 1; for (i = 0; i < (half); ++i) { ans *= m; ans %= mod; } cout << ans << endl; return 0; } if (k > n) { ans = 1; for (i = 0; i < (n); ++i) { ans *= m; ans %= mod; } cout << ans << endl; return 0; } if (k % 2 == 0) { printf("%d\n", m); return 0; } printf("%d\n", m * m); }
#include <bits/stdc++.h> using namespace std; ifstream fin("input.txt"); const long long mod = 1e9 + 7; int main() { long long n, k, m, i, ans = 0; cin >> n >> m >> k; if (k == 1 || k > n) { ans = m; for (i = 1; i < n; i++) { ans *= m; ans %= mod; } cout << ans; return 0; } if (k == n) { ans = m; for (i = 1; i < (n + 1) / 2; i++) { ans *= m; ans %= mod; } cout << ans; return 0; } if (k % 2 == 0) cout << m; else cout << m * m; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, k; int mod = 1e9 + 7; bool mp[5000], ok[5000][5000]; void dfs(int t) { mp[t] = true; for (int i = 0; i < n; i++) { if (!mp[i] && ok[t][i]) dfs(i); } } int main() { cin >> n >> m >> k; for (int i = 0; i < n - k + 1; i++) { for (int j = 0; j < k; j++) ok[i + j][i + k - j - 1] = true; } long long sum = 1; for (int i = 0; i < n; i++) { if (!mp[i]) { sum = sum * m % mod; dfs(i); } } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long binpow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) { res *= a; res %= mod; } a *= a; a %= mod; n >>= 1; } return res; } int main() { long long n, m, k; cin >> n >> m >> k; if (k == 1 && n != 1) cout << binpow(m, n); else if (k > n) cout << binpow(m, n); else if (k < n && k % 2 == 1) cout << binpow(m, 2); else if (k < n && k % 2 == 0) cout << m; else cout << binpow(m, (n + 1) / 2); }
#include <bits/stdc++.h> using namespace std; const int B = 1e9 + 7; const int N = 2e3 + 10; int n, m, k; bool vis[N]; long long mypow(long long a, long long n) { if (n == 0) return 1; if (n & 1) return mypow(a, n - 1) * a % B; return mypow(a * a % B, n >> 1); } bool in(int x) { return x < n && x >= 0; } void dfs(int x) { vis[x] = 1; int f = (k & 1) ? 2 : 1; for (int i = f; i < k; i += 2) { int tx = x + i; int txx = x - i; int tmp = k / 2 - (i + 1) / 2; if (in(x - tmp) && in(tx + tmp)) { if (!vis[tx]) { dfs(tx); } } if (in(x + tmp) && in(txx - tmp)) { if (!vis[txx]) { dfs(txx); } } } } int main() { scanf("%d%d%d", &n, &m, &k); int t = 0; for (int i = 0; i < n; ++i) { if (!vis[i]) { dfs(i); t++; } } printf("%I64d\n", mypow(m, t)); return 0; }
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-8; const int MOD = 1000000007; int main() { istream &fin = cin; ostream &fout = cout; FILE *fpin = stdin; FILE *fpout = stdout; int n, m, k; fin >> n >> m >> k; if (k > n || k == 1) { int res = 1; for (int i = 0; i < n; i++) { res = (long long)res * m % MOD; } fout << res << endl; } else if (k == n) { int res = 1; for (int i = 0; i < (k + 1) / 2; i++) { res = (long long)res * m % MOD; } fout << res << endl; } else { if (k & 1) { int res = m * m % MOD; fout << res << endl; } else { fout << m << endl; } } }
#include <bits/stdc++.h> using namespace std; long long mpow(long long n, long long b) { long long res = 1; for (int i = 1; i <= b; i++) res = (res * n) % 1000000007; return res; } int main() { long long n, m, k, ans = 0; scanf("%I64d%I64d%I64d", &n, &m, &k); if (k == 1 || k > n) ans = mpow(m, n); else if (k == n) ans = mpow(m, k % 2 + k / 2); else if (k % 2) ans = m * m; else ans = m; printf("%I64d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; class DisjointSet { public: explicit DisjointSet(int n) { whichset_ = vector<int>(n); height_ = vector<int>(n, 1); for (int i = 0; i < n; ++i) whichset_[i] = i; } int Find(int node) { if (whichset_[node] == node) return node; return (whichset_[node] = Find(whichset_[node])); } void Merge(int first_node, int second_node) { int h1 = height_[Find(first_node)]; int h2 = height_[Find(second_node)]; if (h1 < h2) { whichset_[Find(first_node)] = Find(second_node); return; } whichset_[Find(second_node)] = Find(first_node); if (h2 < h1) return; ++height_[Find(second_node)]; } private: vector<int> whichset_; vector<int> height_; }; long long MODU = 1000000007LL; int main() { int n, m, k; cin >> n >> m >> k; DisjointSet ds(n); for (int(i) = 0; (i) < (n); ++(i)) { if (i + k <= n) { for (int(j) = 0; (j) < (k); ++(j)) ds.Merge(i + j, i + k - j - 1); } } set<int> s; for (int(i) = 0; (i) < (n); ++(i)) s.insert(ds.Find(i)); long long ret = 1LL; for (int(i) = 0; (i) < (((int)(s).size())); ++(i)) { ret *= (long long)m; ret %= MODU; } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; int pr[3000]; int find(int p) { return pr[p] == p ? p : (pr[p] = find(pr[p])); } int main() { int n, m, k; cin >> n >> m >> k; int i, j, u, v, pu, pv; for (i = 0; i < n; i++) pr[i] = i; for (i = 0, j = k - 1; j < n; i++, j++) { u = i; v = j; while (u < v) { pu = find(u); pv = find(v); if (pu != pv) { pr[pu] = pv; } u++; v--; } } set<int> s; for (i = 0; i < n; i++) s.insert(find(i)); int p = s.size(); long long b = m, r = 1; while (p) { if (p & 1) r = (r * b) % 1000000007; b = (b * b) % 1000000007; p >>= 1; } cout << r << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18; bool prime[1000009]; void SieveOfEratosthenes(long long n) { memset(prime, true, sizeof(prime)); for (long long p = 2; p * p <= n; p++) { if (prime[p] == true) { for (long long i = p * p; i <= n; i += p) { prime[i] = false; } } } } long long power(long long x, long long y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } long long power1(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { res *= a; } a = a * a; b >>= 1; } return res; } long long mod_power(long long a, long long b, long long m) { long long res = 1; a %= m; while (b) { if (b & 1) { res = res * a % m; } a = a * a % m; b >>= 1; } return res; } long long printDivisors(long long n) { long long count = 0; for (long long i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) count++; else printf("%d %d ", i, n / i); } } } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long long min(long long a, long long b) { if (a < b) return a; else return b; } long long d, x, y; void extendedEuclid(long long a, long long b) { if (b == 0) { d = a; x = 1; y = 0; extendedEuclid(b, a % b); } else { long long temp = x; x = y; y = temp - (a / b) * y; } } long long stringmod(string s, long long m) { long long res = 0; for (long long i = 0; i < s.length(); i++) { res = (res * 10 + (long long)s[i] - '0') % m; } return res; } long long fact[200005]; long long nCr(long long n, long long r) { long long ans = fact[n]; ans = (ans * mod_power(fact[n - r], 1000000007 - 2, 1000000007)) % 1000000007; ans %= 1000000007; ans %= 1000000007; return ans; } bool compare(const pair<long long, string> &a, const pair<long long, string> &b) { if (a.first == b.first) return (a.second < b.second); else return (a.first > b.first); } long long min4(long long a, long long b, long long c, long long d) { return min(min(a, b), min(c, d)); } long long par[100001]; long long size1[100001] = {0}; long long find(long long x) { if (par[x] != x) { par[x] = find(par[x]); } return par[x]; } void unionset(long long x, long long y) { long long xr = find(x); long long yr = find(y); if (size1[xr] >= size1[yr]) { par[yr] = xr; size1[xr] += size1[yr]; size1[yr] = 0; } else { par[xr] = yr; size1[yr] += size1[xr]; size1[xr] = 0; } } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long n, m, k; cin >> n >> m >> k; for (long long i = 1; i <= n; i++) { size1[i] = 1; par[i] = i; } for (long long i = 1; i <= n - k + 1; i++) { long long x = i; long long y = i + k - 1; while (x < y) { if (find(x) != find(y)) unionset(x, y); x++; y--; } } long long ans = 1; for (long long i = 1; i <= n; i++) { if (size1[i]) ans = (ans * m) % 1000000007; } cout << ans << endl; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; ostream cnull(NULL); const int INF = 1000 * 1000 * 1000; const long long LINF = 1LL * INF * INF; const int MAX = 100010; const long double PI = acos(-1.); const double EPS = 1e-6; const long long mod = INF + 7; int n, m, k; long long binpow(long long a, long long n) { long long res = 1; while (n) { if (n % 2) { res *= a; res %= mod; } a *= a; a %= mod; n /= 2; } return res; } int main() { ios_base::sync_with_stdio(0); cin >> n >> m >> k; if (k > n) { cout << binpow(m, n) << endl; return 0; } if (k == n) { cout << binpow(m, (n + 1) / 2) << endl; return 0; } if (k == 1) { cout << binpow(m, n) << endl; return 0; } if (k % 2 == 1) { cout << m * m << endl; return 0; } cout << m << endl; return 0; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 45; const int mod = 1000000000 + 7; int n, m, len; bool visi[maxn]; bool dfs(int dx) { visi[dx] = 1; int nxt = dx + len; if (visi[nxt] == false) { dfs(nxt); } } int pw(int base, int e) { if (e == 0) return 1; else if (e % 2 == 0) { int x = pw(base, e / 2); return (x * (long long)x) % mod; } else { return (base * (long long)pw(base, e - 1)) % mod; } } int mark[maxn]; int main() { cin >> n >> m >> len; if (n == len) { int exp = (n / 2) + (n % 2); cout << pw(m, exp) << endl; } else if (len == 1 || len > n) { cout << pw(m, n) << endl; } else if (len % 2 == 0) { cout << m << endl; } else { cout << m * m << endl; } return 0; for (int i = 0; i < n; ++i) { if (mark[i]) continue; mark[i] = i + 1; bool done = false; while (done == false) { done = 1; for (int i = 0; i <= n - len; ++i) { for (int j = 0; j < len; ++j) { if (mark[i + j] == 0) continue; int bff = (-j + len - 1) % (len); if (mark[i + bff]) continue; mark[i + bff] = mark[i + j]; done = 0; } } } } for (int i = 0; i < n; ++i) cout << mark[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> long long power(int m, int pow) { if (pow == 1) return m; else { long long val = power(m, pow / 2); val = (val * val) % 1000000007; if (pow % 2) val = (val * (long long)m) % 1000000007; return val; } } int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); if (k == 1) printf("%d\n", power(m, n)); else { if (n > k) { if (k % 2) printf("%d\n", (m * m) % 1000000007); else printf("%d\n", m); } else if (n == k) { int pow = k / 2 + k % 2; printf("%I64d\n", power(m, pow)); } else { printf("%d\n", power(m, n)); } } return 0; }