Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class D401 { int n, mod; int[] num; long[][] memo; public long dp(int mask, int curMod) { if(Integer.bitCount(mask) == n) return curMod == 0 ? 1 : 0; if(memo[curMod][mask] != -1) return memo[curMod][mask]; long ans = 0;...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; int digit[105]; long long Num; long long dp[1 << 18][105]; int cnt[10]; int main() { scanf("%lld%d", &Num, &m); while (Num) { digit[++n] = Num % 10; cnt[Num % 10]++; Num /= 10; } dp[0][0] = 1; for (int i = (0), i_end_ = ((1 << n) - 1); i <= i...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int main() { long long n; int m; cin >> n >> m; ostringstream oss; oss << n; string const number = oss.str(); int const digits = (int)number.size(); int const all_digits_mask = ((long long)1 << digits) - 1; vector<vector<long long> > dp(all_digits_mask + 1...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Round235_D { char[] number; int len; long[] val; int M; long memo[][]; public long go(int mask, int reminder, int cnt) { ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.util.*; public class p401d { BufferedReader in; PrintWriter out; StringTokenizer st; String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (Exception e) { ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[(1 << 18)][111]; int main() { int n, m, x, y, i, pre; char str[20]; int a[20], j, k, ii; while (cin >> str >> m) { n = strlen(str); for (i = 0; i < n; i++) a[i] = str[i] - '0'; sort(a, a + n); memset(dp, 0, sizeof(dp)); dp[0][0] = 1;...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m, dp[300010][110]; bool vis[11]; vector<long long> plc; int main() { long long i, j, k; cin >> n >> m; while (n != 0) { plc.push_back(n % 10); n /= 10; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (i = 0; i < (1 << (long long)plc.size()...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int m, a[20], cnt[15]; long long n, fact[20], dp[262150][105]; int getbit(int a, int i) { return ((a >> (i - 1)) & 1); } int batbit(int a, int i) { return ((1 << (i - 1)) | a); } int main() { int i, j, k, x, len = 0; long long n1; cin >> n >> m; n1 = n; fact[0] = ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int w[20], cnt = -1, m; long long f[(1 << 18) + 10][110], n; bool vis[10]; int main() { for (cin >> n >> m; n; n /= 10) w[++cnt] = n % 10; f[0][0] = 1; for (int s = 1; s < 1 << cnt + 1; s++) { memset(vis, 0, sizeof(vis)); for (int i = 0; i <= cnt; i++) { ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.IOException; import java.util.Arrays; import java.io.UnsupportedEncodingException; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the to...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1 << 18; long long ans[N][100]; long long tot, a[25], m, n; long long dfs(int st, int yu, int flag) { if (st == (1 << tot) - 1) return yu == 0; if (!flag && ans[st][yu] != -1) return ans[st][yu]; bool v[10] = {0}; long long res = 0; for (int i = 1; i...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; public class cf401D { static BufferedReader br; static Scanner sc; static PrintWriter out; public static void initA() { try { br = new BufferedReader(new InputStreamReader(System.in)); ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long int i, j, n, m, ans, freq[20], dp[1 << 18][120], limit, mask, temp, d, fact[100]; vector<long long int> v; int main() { cin >> n >> m; temp = n; while (temp) { d = temp % 10; freq[d]++; temp = temp / 10; v.push_back(d); } fact[0] = 1;...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.Reader; import java.util.InputMismatchException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.util.*; public class Solution{ InputStream is; static PrintWriter out; String INPUT = ""; static long mod = (long)1e9+7L; long[][] dp; long[] pow10; char[] a; int N; public void solve(){ pow10 = new long[19]; pow10[0] = 1; for(int i = 1; i < 19; i++){ pow10[i] = pow10[...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; string num; int m, n; long long dp[1 << 18][100]; int cnt[10], fact[20]; long long solve(int cnt, int mask, int rem) { if (cnt == n) { if (rem == 0) return 1; return 0; } long long &ret = dp[mask][rem]; if (ret != -1) return ret; ret = 0; int vis[10]; ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } const double EPS = 1e-...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; int m; cin >> s >> m; int n = s.size(); int N = 1 << n; long long int dp[N][m]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 0; i < N; ++i) { for (int j = 0; j < m; ++j) ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.Scanner; import java.util.Arrays; public class D{ public static void main(String[] args){ Scanner in = new Scanner(System.in); long n = in.nextLong(); int mod = in.nextInt(); long base[] = new long[18]; int nLength = 0; //convert to base 10 while(n > 0){ base[nLength++] = n % 10L; ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<vector<int>, int>, long long> ma; long long dp[(1 << 18)][101]; int main() { srand((unsigned int)time(NULL)); long long n, m; int dig[20], id = 0, ten[20], cnt[10] = {}; ten[0] = 1; cin >> n >> m; for (int i = 1; i <= 19; i++) ten[i] = (ten[i - 1] * 10)...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
//package round235; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class D { InputStream is; PrintWriter out; String INPUT = ""; void solve() { long n = nl(); in...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int l; int mo; string n; long long dp[1 << 18][100]; long long coun[10]; int fastmod[10004]; void pre() { for (int i = (1); i <= (10004 - 1); ++i) { fastmod[i] = i % mo; } } long long solve(int mask, int m) { if (mask == (1 << l) - 1) return m == 0; if (dp[mask]...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int num[25], cnt; long long dp[(1 << 18)][100]; long long fac[30], bcnt[10]; int main(void) { long long n, m; scanf("%lld%lld", &n, &m); for (; n; num[++cnt] = n % 10, n /= 10) ; dp[0][0] = 1; for (register int i = 0; i < (1 << cnt); ++i) for (register int...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int bmod(int a, int b, int m) { if (b == 0) return 1; int x = bmod(a, b / 2, m); x = (x * x) % m; if (b % 2 == 1) x = (x * a) % m; return x; } long long powr(long long n, long long m) { long long ans = 1;...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.util.*; /* * Heart beats fast * Colors and promises * How to be brave * How can I love when I am afraid... */ public class Main { public static void main(String[]args) throws Exception { long n=nl(); int m=ni(); int te=0; int lol[]=new int[64]; long lolo=n; for(...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; public class cf401D { static BufferedReader br; static Scanner sc; static PrintWriter out; public static void initA() { try { br = new BufferedReader(new InputStreamReader(System.in)); ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } long long n; int m; bool used[10]; int bits[1 << 18]; long long base[18]; long long f[1 << 18][100]; int main() { cin >> n >> m; base[0] = 1; for (int i = 1; i < 18; ++i) base[i] = base[i - 1] * 10; bits[0] ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[1 << 18][111]; int cnt[11]; int a[11]; string s; int m; int main() { cin >> s >> m; int l = s.size(); memset(cnt, 0, sizeof(cnt)); memset(a, 0, sizeof(a)); memset(dp, 0, sizeof(dp)); for (int i = 0; i < l; i++) cnt[s[i] - '0']++; for (int(i) = (1)...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import com.sun.org.apache.xml.internal.utils.StringComparable; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.*; public class Main { public static void main(String[] args) { // Test.te...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> const int maxn = 3e5 + 123; using namespace std; int n, m; int cnt[10]; long long dp[(1 << 18) + 123][105]; int main() { string s; cin >> s; cin >> m; for (int i = 0; i < s.size(); i++) cnt[s[i] - '0']++; for (int i = 0; i < s.size(); i++) if (s[i] != '0') dp[(1 << i)][(s[i] - '0'...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, limit, Now; string s; long long arr[12]; long long DP[102][(1 << 18) + 3]; long long dp(int rem, int mask) { if (mask == limit) return !rem; long long &ret = DP[rem][mask]; if (~ret) return ret; ret = 0; int d5l = 0; for (int i = 0; i < n; ++i) { N...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int siz; long long f[(1 << 18)][105]; bool chk[20]; int getbit(int mask, int k) { return ((mask >> (k - 1)) & 1); } int cnt(int mask) { int tmp = 0; for (int i = 1; i <= siz; i++) if (getbit(mask, i)) tmp++; return tmp; } int main() { string s; int m; cin >>...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long d[262145][101], n, k, m, sz; long long po[1005], fc[50], G[50], PP; string s; int main() { int M = int(1e9) + 7; cin >> s >> m; fc[0] = 1; for (int i = 1; i <= 18; i++) fc[i] = (fc[i - 1] * i); n = s.size(); for (int i = 0; i < n; i++) G[s[i] - '0']++;...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; public clas...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
/** * ******* Created on 20/12/19 9:09 PM******* */ import java.io.*; import java.util.*; public class D401 implements Runnable { private static final int MAX =3* (int) (1E5 + 5); private static final int MOD = (int) (1E9 + 7); private static final long Inf = (long) (1E14 + 10); long[][]dp = new l...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWri...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int l = -1; long long N, M, f[262150][105], w[20], sum[10], jc[20]; int main() { cin >> N >> M; for (; N; N /= 10) w[++l] = N % 10; for (int i = 0; i <= l; ++i) { sum[w[i]]++; if (w[i]) f[1 << i][w[i] % M] = 1; } for (int i = 1; i <= (1 << l + 1) - 1; ++i)...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.*; import java.math.*; import java.io.*; public class CF401D { long go(int mod, int mask) { if(mask == full) return mod > 0 ? 0 : 1; if(dp[mod][mask] != -1) return dp[mod][mask]; long res = 0, tried = 0; for(int i = len - 1 ; i >= 0 ; i--) { if((mask & (1 << i)) != 0) continue; if(mask ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.Arrays; import java.util.Scanner; public class cf401d_10DIMENSIONSBABY { static int[] digitcounts = new int[10]; static int len, mod; static long[][][][][][][][][][][] memo; public static long dp(int[] counts, int cmod) { if (memo[counts[0]][counts[1]][counts[2]][counts[3]][counts[4]][counts[5...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long f[1 << 18][100]; int a[100]; int main() { long long n, m; int N = 0; cin >> n >> m; for (; n; n /= 10) a[N++] = n % 10; sort(a, a + N); int mask, k; f[0][0] = 1; for (mask = 0; mask < (1 << N); mask++) for (k = 0; k < m; k++) if (f[mask][...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) { solve(); } static int mod, state[] = new int[11]; static Long dp[][]; private static void solve() { ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.StringTokenizer; public class RomanAndNumbers { static char[] arr; ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int tim[10]; int dig[19]; long long dp[(1 << 18)][100]; bool flag[10]; void solve(long long n, int mod); int main() { long long n; int mod; cin >> n >> mod; solve(n, mod); return 0; } void solve(long long n, int mod) { memset(tim, 0, sizeof tim); int len = 0; ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) { for (long long i = 0; i < A.size(); i++) os << A[i] << " "; os << endl; return os; } template <> ostream &operator<<(ostream &os, const vector<vector<long long> > &A) { long long N = A.size...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const int MAX = 18; long long n; int m; int digs; int dig[MAX]; int cnt[MAX]; long long dp[1 << MAX][105]; long long fact[MAX]; int main() { cin >> n >> m; fact[0] = 1; for (int i = 1; i < MAX; i++) { fact[i] = fact[i - 1] * i; } while (n > 0) { dig[digs] ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; /* br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); br = new Bu...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int num[20], sum[10]; long long dp[1 << 18][105], fac[20]; void init() { fac[0] = 1; for (int i = 1; i <= 17; ++i) fac[i] = fac[i - 1] * i; } int main() { int l = 0, m; long long n, res = 1; scanf("%lld%d", &n, &m); while (n) { num[l++] = n % 10; n /= 10...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.HashMap; import java.util.Scanner; public class cf401d { public static long factorial(int a) { long ret = 1; for (int i = 2; i <= a; i++) ret *= i; return ret; } public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); int m = in.nextInt...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class P401D { static long[][] dp; public static void main(String[] args) { Scanner scan = new Scanner(System.in); char[] n = scan.next().toCharArray(); for (int i = 0; i < n.length; i++) n[i] -= '0'; int m = scan.nextI...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long fact[20]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; fact[0] = 1; for (long long i = 1; i < 20; i++) { fact[i] = fact[i - 1] * i; } long long n, m; cin >> n >> m; vector<long long> digits; while (n > 0) { ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const int N = 2e6 + 10; vector<int> V[20]; int cnt[N], pos[N], dig[20], num[13]; vector<long long> f[20][105]; int main() { for (int i = 1; i <= 2000000; i++) cnt[i] = cnt[i >> 1] + (i & 1); long long n, m; cin >> n...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int lowbit(int x) { return x & (-x); } const int maxn = 105; int tp, m, a[30], vis[10]; long long n, dp[1 << 18][maxn]; int main(void) { scanf("%lld%d", &n, &m); while (n) a[tp++] = n % 10, n /= 10; dp[0][0] = 1; for (int i = 1; i < (1 << tp); ++i) { memset(vis,...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[1 << 18][110]; int main() { int m, n; string s; cin >> s >> m; n = s.size(); sort(s.begin(), s.end()); dp[0][0] = 1; for (int i = 0; i < 1 << n; ++i) for (int j = 0; j < m; ++j) if (dp[i][j]) for (int k = 0; k < n; ++k) ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const int mB = 1 << 18; const int mM = 105; long long cnt[mB][mM]; int masks[mB]; bool compareMask(int m1, int m2) { return __builtin_popcount(m1) < __builtin_popcount(m2); } int frequency[10]; int main() { long long n; int mod; cin >> n >> mod; int nBits = 0, bit...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const int W = 18, M = 100; int m, len; long long n, f[1 << W | 7][M | 7]; vector<int> d; inline void Pre() { memset(f, -1, sizeof f); } inline long long Dfs(register int w, register int st, register int sum) { if (!w) return sum == 0; if (~f[st][sum]) return f[st][sum];...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9 + 7; const int inf = 1061109567; const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int digit[20], m, cnt; long long dp[1 << 18][101]; long long dfs(int s, int num) { if (num == 0 && s == 0) ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; string s; int n, m, a[18]; int freq[18]; long long fact[18]; long long dp[1 << 18][101]; int main() { fact[0] = 1; for (int i = 1; i < 18; ++i) { fact[i] = fact[i - 1] * i; } cin >> s >> m; n = s.length(); for (int i = 0; i < n; ++i) { a[i] = s[i] - '0';...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; string S; int MOD; int len; long long dp[1 << 18][100]; int cnt[1 << 18]; int bits[1 << 18]; int DMASKS[1 << 18]; int powers[20]; int orig; long long solve(int mask, int mod) { if (mask == 0) { return mod == 0; } long long &ret = dp[mask][mod]; if (ret != -1) re...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int arr[19]; int md; int n; long long dp[(1 << 18)][100]; long long fact[19]; std::map<int, int> m1; long long first(int mask, int m) { if (mask == (1 << n) - 1) return m == 0; if (dp[mask][m] != -1) return dp[mask][m]; long long ans = 0; fo...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> #pragma gcc optimize("Ofast") using namespace std; unsigned long long dp[1 << 18][100] = {0}, f[10] = {0}, m, d = 1; int main() { string n; cin >> n >> m; for (int i = 0; i < n.size(); i++) d *= ++f[n[i] -= '0']; dp[0][0] = 1; unsigned long long all = (1 << n.size()) - 1; for (unsig...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) { solve(); } static int mod, state[] = new int[11]; static long dp[][]; private static void solve() { ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; string s; long long n, mod, fact[18], dp[1 << 18][100], cnt[26], ans; int main() { cin >> s >> mod; n = s.size(); fact[0] = dp[0][0] = 1; for (int i = 1; i < 18; ++i) fact[i] = fact[i - 1] * i; for (auto &it : s) ++cnt[it - '0']; for (int mask = 0; mask < (1 << ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long n, k, i, f[100], j, ii, dp[(1LL << 18)][101], s[11], d[20]; char ss[100]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> ss >> k; n = strlen(ss); for (i = 0; i < n; i++) f[i] = ss[i] - '0', s[f[i]]++; sort(f, f + n); d[0] = 1; fo...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m; long long dp[1 << 18][110]; vector<int> digits; long long solve(int mask, int k) { long long res = 0; int p = digits.size() - 1 - __builtin_popcount(mask); if (p < 0) return k == 0; if (dp[mask][k] != -1) return dp[mask][k]; long long mult = pow(10...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long w[20], cnt = -1, vis[10], n, m, f[(1 << 18) + 10][105]; signed main() { cin >> n >> m; while (n) { w[++cnt] = n % 10; n /= 10; } f[0][0] = 1; for (long long s = 1; s < 1 << (cnt + 1); s++) { memset(vis, 0, sizeof(vis)); for (long long i =...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[1 << 18][110], per = 1, fact[12], cnt[12]; int main() { int m, i; char str[50]; scanf("%s%d", str, &m); int n = strlen(str); for (i = 0; i < n; i++) cnt[str[i] - '0']++; dp[0][0] = 1; for (int i = 0; i < (1ll << n); i++) { for (int j = 0; j < ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; constexpr int N = (1 << 18) + 10; constexpr int M = 100 + 10; long long m, x, dp[N][M], h, n, fact[M], p, sz; vector<int> digit; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; while (n) { digit.push_back(n % 10); n /...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; inline long long Read() { long long res = 0, f = 1; char c; while (c = getchar(), c < 48 || c > 57) if (c == '-') f = 0; do res = (res << 3) + (res << 1) + (c ^ 48); while (c = getchar(), c >= 48 && c <= 57); return f ? res : -res; } template <class T> inlin...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.text.DecimalFormat; import java.util.*; public class Main { static int mod = (int)1e9+7; static int N = 18; static int S = 1<<N; int m, mx; int[] ar = new int[N]; int dep; long n; long[][] d = new long[S][105]; void work() throws Exception { //in = new BufferedReader(new ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int m, bit, sum; int a[20]; long long dp[262150][105]; long long ten[20]; long long n, ans; bool mark[15]; map<long long, int> pos; void init() { ten[0] = 1; for (int i = 1; i < 18; i++) ten[i] = ten[i - 1] * 10; for (int i = 1; i <= 18; i++) pos[1 << (i - 1)] = i; ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[1 << 18][100], n, m, a[20]; int waight[20], w[20][20], pre[20], endstate; long long solve(int state, int mod, int ai) { if (state == endstate) return mod == 0; long long &ret = dp[state][mod]; if (ret != -1) return ret; ret = 0; int nmod, nstate; fo...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.util.*; public class C235D { public static StringTokenizer st; public static void nextLine(BufferedReader br) throws IOException { st = new StringTokenizer(br.readLine()); } public static String next() { return st.nextToken(); } pu...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Created by chinh on 7/19/14. */ public class R235D2D { static long factorial(int x){ long ret = 1; for(int i=2; i<=x; i++) ret*=i; return ret; } public static void main(String...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, m; cin >> n >> m; stringstream ss; ss << n; string ns = ss.str(); if (ns.size() == 1) { if (m > 1) { cout << 0 << endl; } else { cout << 1 << endl; } } else { vector<int64_t> m10(19); vector<int64_t> fact...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.util.*; public class D { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int count(long x) { int res = 0; while (x > 0) { if (x % 2 != 0) res++; x /= 2; } return res; } public void run() { String s = in.next(); int...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { FastIO io; // File names!!! void solve() throws IOException { char[] a = io.nextCharArray(); int[] count = new int[10]; for (char c : a) { count[c - '0']++; } int...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class D { static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static void exit() { sc.close(); out.close(); System.exit(0); } static int [] digits; static int m; public st...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> long long solve(std::string s, int mod) { const int n = (int)s.size(); std::vector<std::vector<long long>> cnt(1 << n, std::vector<long long>(mod, 0)); std::vector<long long> pow10(1 + n, 1 % mod); for (int i = 1; i <= n; ++i) { pow10[i] = p...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.*; import java.io.*; import java.text.*; public class CF_401D{ //SOLUTION BEGIN void pre() throws Exception{} void solve(int TC) throws Exception{ long N = nl(); M = ni(); n = ""+N; L = n.length(); long[] pow = new long[L+1]; pow[0] = 1; ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.HashMap; import java.util.Scanner; public class cf401d { public static long factorial(int a) { long ret = 1; for (int i = 2; i <= a; i++) ret *= i; return ret; } public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); int m = in.nextInt...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<ll>; const int B = 18; const int N = 1 << B; const int M = 100; vector<vi> dp; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; ll pw = 1; ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class D { static StringTokenizer st; static BufferedReader br; static PrintWr...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.util.*; public class D { Scanner sc = new Scanner(System.in); void doIt() { char [] c_n = sc.next().toCharArray(); int m = sc.nextInt(); int len = c_n.length; int [] n = new int[len]; int [] dcnt = new int[10]; long div = 1L; for(int i = 0; i < len; i++) { n[i] = (int)(c_n[i] - '0'); ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { InputReader in = new InputReader(); Prin...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.StringTokenizer; /** * * * 3 2 3 5 * -2 -1 4 -1 2 7 3 * * * @author pttrung */ public class D { public sta...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.util.*; public class cf401d { static FastIO in = new FastIO(), out = in; static int n, MOD; static int[] v; static long[][] memo; public static void main(String[] args) { String x = in.next().trim(); n = x.length(); v = new int[n]; for(int i=0; i<n; i++) { ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedInputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Linked...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long n; int m, cnt; int s[20], p[20][102], ss[10]; long long aa, f[262150][102], jc[20]; int main() { int x = 0, x1 = 0, x2 = 0; long long a = 0; cin >> n >> m; a = n; while (a) { s[++cnt] = a % 10; a /= 10; } jc[0] = 1; for (int i = 1; i <= cnt...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; string s; int m; long long dp[1 << 18][100]; long long calc(int i, int mask, int mod) { if (i == s.size()) return mod == 0; long long &ret = dp[mask][mod]; if (ret != -1) return ret; ret = 0; for (int j = 0; j < s.size(); ++j) if (!((mask >> j) & 1)) { i...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; public class Main{ public static class FastReader { BufferedReader br; StringTokenizer root; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while ...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; int a[100]; long long f[1 << 18][100]; int main() { int m; long long n; cin >> n >> m; int N = 0; for (; n; n /= 10) a[N++] = n % 10; sort(a, a + N); f[0][0] = 1; for (int mask = 0; mask < (1 << N); mask++) for (int k = 0; k < m; k++) if (f[mask][k...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[1LL << 18][101]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string n; long long m; cin >> n >> m; sort(n.begin(), n.end()); dp[0][0] = 1; for (long long mask = 0; mask < (1LL << (long long)n.length()); mask++) { ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; string s; int n; int m; long long cnt[1 << 18][100]; int main() { ios_base::sync_with_stdio(false); cin >> s >> m; n = s.size(); cnt[0][0] = 1; for (int mask = 0; mask < 1 << n; mask++) { for (int mod = 0; mod < m; mod++) { for (int i = 0; i < n; i++) { ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; long long dp[(1 << 18)][101], n, m; long long v[22], gigi; string str; int main() { ios::sync_with_stdio(false); cin >> str >> m; n = str.size(); for (int i = str.size() - 1; i >= 0; i--) { if (i == str.size() - 1) v[i] = 1; else v[i] = v[i + 1] ...
CPP
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedInputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Linked...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.*; import java.math.*; import java.util.*; public class Main { InputReader in; PrintWriter out; void run(){ out = new PrintWriter(new OutputStreamWriter(System.out)); in = new InputReader(System.in); solve(); out.flush(); } public static void main(...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparat...
JAVA
401_D. Roman and Numbers
Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are close to number n, modulo m. Number x is considered close to number n mod...
2
10
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(...
CPP