A:
#include <bits/stdc++.h>
using namespace std;
int cnt[20];
int main(){
int l,r;
scanf("%d%d",&l,&r);
for(int i=l; i<=r; i++){
memset(cnt,0,sizeof(cnt));
int tmp = i,tag = 1;
while (tmp) {
if (cnt[tmp % 10]) tag = 0;
cnt[tmp % 10]++;
tmp /= 10;
}
if (tag) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
B:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
int f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e3 + 10;
const LL mod = 1000000007;
LL black[maxn][maxn],white[maxn][maxn];
LL r[maxn],c[maxn];
int main(){
//freopen("/Users/chutong/ACM/data.in","r",stdin);
//freopen("/Users/chutong/ACM/data.out","w",stdout);
int h = read(),w = read(),tag = 1;
for(int i=1; i<=h; i++){
r[i] = read();
for(int j=1; j<=r[i]; j++){
black[i][j] = 1;
}
white[i][r[i]+1] = 1;
}
for(int i=1; i<=w; i++){
c[i] = read();
for(int j=1; j<=c[i]; j++){
if (white[j][i]) tag = 0;
black[j][i] = 1;
}
if (black[c[i]+1][i]) tag = 0;
white[c[i]+1][i] = 1;
}
LL ans = 1;
for(int i=1; i<=h; i++){
for(int j=1; j<=w; j++){
if (!black[i][j] && !white[i][j]){
ans = ans * 2 % mod;
}
}
}
if (tag == 0){
cout << 0 << endl;
}else{
cout << ans << endl;
}
return 0;
}
C:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
int f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7;
std::vector<LL> res;
LL qpow(LL a,LL b){
LL base = a % mod,ans = 1;
while(b){
if (b & 1) ans = ans * base % mod;
base = base * base % mod;
b >>= 1;
}
return ans % mod;
}
int main(){
//freopen("/Users/chutong/ACM/data.in","r",stdin);
//freopen("/Users/chutong/ACM/data.out","w",stdout);
LL x,n;
scanf("%lld%lld",&x,&n);
for(LL i=2; i*i<=x; i++){
if (x % i == 0){
res.push_back(i);
while(x % i == 0){
x /= i;
}
}
}
if (x > 1) res.push_back(x);
LL ans = 1;
for(auto now : res){
LL tmp = now;
for(int i=1; i<=100; i++){
if (tmp > n) break;
else{
LL cnt = n/(LL)tmp;
ans = ans * qpow(now,cnt) % mod;
if (n / tmp < now) break;
else tmp = tmp * now;
}
}
}
cout << ans << endl;
return 0;
}
D:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
map<vector<int>, vector<int>> mp;
vector<int> g[maxn];
int a[maxn];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for (int i=1; i<=m; i++) {
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
for(int i=1; i<=n; i++){
if (g[i].empty()) {
puts("-1");
return 0;
}
sort(g[i].begin(), g[i].end());
mp[g[i]].push_back(i);
}
if (mp.size() != 3){
puts("-1");
return 0;
}
int ans = 1;
for(auto x: mp){
for(auto i : x.second){
a[i] = ans;
}
ans++;
}
for(int i=1; i<=n; i++){
printf("%d%c",a[i],"\n"[i == n]);
}
return 0;
}