submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s193828615
p04015
Java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Created by jaga on 9/6/16. * dpで解けるかな? * 入力の数字を -Aしておき、組み合わせで0が何通り作れるかを考える * dp[j][k] = j番目(0-indexed)までの文字をつかってkが何回作れるか j < N , - N*50 < k < N*50 + 1 * kの値は k + N*50 としておく(負の値の処理のため) * dp[j][k] = dp[j - 1][k] + dp[j-1][k - x[j]] * j-1番目までの数で作ってj番目は使わない + j - 1番目までの数でk-x[j]をつくってjを使う * これに+してx[j]がkのときはdp[j-1][k] = 0でも1足すことになる(コーナーケース) */ public class main { public static void main (String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); String text[] = line.split(" "); int N,A; N = Integer.parseInt(text[0]); A = Integer.parseInt(text[1]); line = br.readLine(); text = line.split(" "); int [] x = new int[N]; for(int i = 0; i < N ; i++){ x[i] = Integer.parseInt(text[i]) - A; // System.out.println(x[i]); } long dp[][] = new long [N][N * 50 * 2 + 1]; int dpl = 50 * N; dp[0][x[0] + dpl] = 1; for(int j = 1; j < N; j++){ for(int k = -1 * N * 50; k < N * 50 + 1; k++){ // System.out.println(k + dpl - x[j]); if(k + dpl - x[j] >= 0 && k + dpl - x[j] <= 50*N*2){ // if(k + dpl - x[j] >= 0 ){ dp[j][k + dpl] = dp[j-1][k + dpl] + dp[j-1][k + dpl - x[j]]; }else { dp[j][k + dpl] = dp[j - 1][k + dpl]; } if(x[j] == k) dp[j][k + dpl] ++; // System.out.println("dp[" + j + "][" + k + "] = " + dp[j][k + dpl]); } } System.out.println(dp[N - 1 ][dpl]); } }
Main.java:17: error: class main is public, should be declared in a file named main.java public class main { ^ 1 error
s790238054
p04015
C++
ga
a.cc:1:1: error: 'ga' does not name a type 1 | ga | ^~
s338017809
p04015
C++
ga
a.cc:1:1: error: 'ga' does not name a type 1 | ga | ^~
s414351566
p04015
C++
test
a.cc:1:1: error: 'test' does not name a type 1 | test | ^~~~
s512003875
p04015
C++
aa
a.cc:1:1: error: 'aa' does not name a type 1 | aa | ^~
s042534107
p04015
C++
#test
a.cc:1:2: error: invalid preprocessing directive #test 1 | #test | ^~~~
s668353681
p04015
C
#include<stdio.h> #include<stdlib.h> typedef long long ll; int N,A; int x[51]; ll dp[51][51][2501]; int max; void solve(){ int i,j,k; ll ans = 0; dp[0][0][0] = 1; for(i = 0; i <= N; i++){ for(j = 0; j <= N; j++){ for(k = 0; k <= N*max; k++){ if(k < x[i] && i >= 1)dp[i][j][k] = dp[i-1][j][k]; else if (i >= 1 && j >= 1 && k >= x[i]) dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]; else if(i+j+k != 0)dp[i][j][k] = 0; } } } for(i = 1; i <= N ; i++){ ans += dp[N][i][i*A]; } printf("%lld\n",ans); }
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s499056647
p04015
C++
//変数名を長くしても伝わらなければ意味がないのじゃ #include <iostream> #include <algorithm> #define int long long using namespace std; int ______________________________________; int kokoropyonpyonmatchi[100000]; int kangaerufurisite[100001]; int l; int q; int mutyotthikaduityaeeeeeeeeee, thikaduityaeeeeeeeeee; int unkonokoun[20][100000]; int nyanyanyanyanyanyanyanyanyanya[20][100000]; int dist(int l, int r) { if (l > r) swap(l, r); return kokoropyonpyonmatchi[r] - kokoropyonpyonmatchi[l]; } bool checkL(int mid) { int i = 19; int pos = mutyotthikaduityaeeeeeeeeee; while (i >= 0) { if ((mid >> i) % 2 == 1) pos = nyanyanyanyanyanyanyanyanyanya[i][pos]; i--; } return (pos <= thikaduityaeeeeeeeeee); } bool checkR(int mid) { int i = 19; int pos = mutyotthikaduityaeeeeeeeeee; while (i >= 0) { if ((mid >> i) % 2 == 1) pos = unkonokoun[i][pos]; i--; } return (pos >= thikaduityaeeeeeeeeee); } bool check(int mid) { if (mutyotthikaduityaeeeeeeeeee >= thikaduityaeeeeeeeeee) return checkL(mid); return checkR(mid); } signed main() { int i, j; cin >> ______________________________________; for (i = 0; i < ______________________________________; i++) cin >> kokoropyonpyonmatchi[i]; cin >> l; j = 0; for (i = 0; i < ______________________________________; i++) { for (j = max(j, i); j < ______________________________________ && dist(i, j) <= l; j++); j--; unkonokoun[0][i] = j; } for (i = 1; i < 20; i++) { for (j = 0; j < ______________________________________; j++) { unkonokoun[i][j] = unkonokoun[i-1][unkonokoun[i-1][j]]; } } j = ______________________________________ - 1; for (i = ______________________________________ - 1; i >= 0; i--) { for (j = min(j, i); j >= 0 && dist(i, j) <= l; j--); j++; nyanyanyanyanyanyanyanyanyanya[0][i] = j; } for (i = 1; i < 20; i++) { for (j = 0; j < ______________________________________; j++) { nyanyanyanyanyanyanyanyanyanya[i][j] = nyanyanyanyanyanyanyanyanyanya[i-1][nyanyanyanyanyanyanyanyanyanya[i-1][j]]; } } cin >> q; for (int i = 0; i < q; i++) { cin >> mutyotthikaduityaeeeeeeeeee >> thikaduityaeeeeeeeeee; mutyotthikaduityaeeeeeeeeee--; thikaduityaeeeeeeeeee--; int stastasta = 0, toritter = ______________________________________ + 5, mendou; while (ed - st >= 2) { mendou = (stastasta + toritter) / 2; if (check(mendou)) { toritter = mendou; } else { stastasta = mendou; } } cout << toritter << endl; } return 0; }
a.cc: In function 'int main()': a.cc:85:24: error: 'ed' was not declared in this scope 85 | while (ed - st >= 2) { | ^~ a.cc:85:29: error: 'st' was not declared in this scope; did you mean 'std'? 85 | while (ed - st >= 2) { | ^~ | std
s887334844
p04015
C++
//変数名を長くしても伝わらなきゃ意味がないのじゃ #include <iostream> #include <algorithm> #define int long long using namespace std; int ______________________________________; int kokoropyonpyonmatchi[100000]; int kangaerufurisite[100001]; int l; int q; int mutyotthikaduityaeeeeeeeeee, thikaduityaeeeeeeeeee; int unkonokoun[20][100000]; int nyanyanyanyanyanyanyanyanyanya[20][100000]; int dist(int l, int r) { if (l > r) swap(l, r); return kokoropyonpyonmatchi[r] - kokoropyonpyonmatchi[l]; } bool checkL(int mid) { int i = 19; int pos = mutyotthikaduityaeeeeeeeeee; while (i >= 0) { if ((mid >> i) % 2 == 1) pos = nyanyanyanyanyanyanyanyanyanya[i][pos]; i--; } return (pos <= thikaduityaeeeeeeeeee); } bool checkR(int mid) { int i = 19; int pos = mutyotthikaduityaeeeeeeeeee; while (i >= 0) { if ((mid >> i) % 2 == 1) pos = unkonokoun[i][pos]; i--; } return (pos >= thikaduityaeeeeeeeeee); } bool check(int mid) { if (mutyotthikaduityaeeeeeeeeee >= thikaduityaeeeeeeeeee) return checkL(mid); return checkR(mid); } signed main() { int i, j; cin >> ______________________________________; for (i = 0; i < ______________________________________; i++) cin >> kokoropyonpyonmatchi[i]; cin >> l; j = 0; for (i = 0; i < ______________________________________; i++) { for (j = max(j, i); j < ______________________________________ && dist(i, j) <= l; j++); j--; unkonokoun[0][i] = j; } for (i = 1; i < 20; i++) { for (j = 0; j < ______________________________________; j++) { unkonokoun[i][j] = unkonokoun[i-1][unkonokoun[i-1][j]]; } } j = ______________________________________ - 1; for (i = ______________________________________ - 1; i >= 0; i--) { for (j = min(j, i); j >= 0 && dist(i, j) <= l; j--); j++; nyanyanyanyanyanyanyanyanyanya[0][i] = j; } for (i = 1; i < 20; i++) { for (j = 0; j < ______________________________________; j++) { nyanyanyanyanyanyanyanyanyanya[i][j] = nyanyanyanyanyanyanyanyanyanya[i-1][nyanyanyanyanyanyanyanyanyanya[i-1][j]]; } } cin >> q; for (int i = 0; i < q; i++) { cin >> mutyotthikaduityaeeeeeeeeee >> thikaduityaeeeeeeeeee; mutyotthikaduityaeeeeeeeeee--; thikaduityaeeeeeeeeee--; int stastasta = 0, toritter = ______________________________________ + 5, mendou; while (ed - st >= 2) { mid = (stastasta + toritter) / 2; if (check(mendou)) { toritter = mendou; } else { stastasta = mendou; } } cout << toritter << endl; } return 0; }
a.cc: In function 'int main()': a.cc:85:24: error: 'ed' was not declared in this scope 85 | while (ed - st >= 2) { | ^~ a.cc:85:29: error: 'st' was not declared in this scope; did you mean 'std'? 85 | while (ed - st >= 2) { | ^~ | std a.cc:86:25: error: 'mid' was not declared in this scope 86 | mid = (stastasta + toritter) / 2; | ^~~
s042414788
p04015
C++
#include<cstdio> #include <map> #include<iostream> #include<string.h> #include<algorithm> using namespace std; typedef __int64 LL; int x[60];; long long dp[60][60][2600]; int main() { int n, a; scanf("%d%d", &n, &a); for(int i = 1; i <= n; ++i) scanf("%d", &x[i]); for(int i = 0; i <= n; ++i) dp[i][0][0] = 1; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= i; ++j) { for(int k = 0; k <= 2500; ++k) { if(k - x[i] >= 0) dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]; dp[i][j][k] += dp[i - 1][j][k]; } } } long long ans = 0; for(int i = 1; i <= n; ++i) ans += dp[n][i][a * i]; printf("%lld\n", ans); return 0; }
a.cc:8:9: error: '__int64' does not name a type; did you mean '__int64_t'? 8 | typedef __int64 LL; | ^~~~~~~ | __int64_t
s681097048
p04015
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define ITR(v,c) for(auto v=begin(c);v!=end(c);v++) #define FOR(v,a,n) for(int v=a;v<(int)(n);v++) #define FORE(x,arr) for(auto &x:arr) #define REP(v,n) FOR(v,0,n) #define ALL(c) begin(c),end(c) const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0}; const int INF = 1e9; const ll INFLL = 1e18; template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){ os<<"("<<p.first<<","<<p.second<<")";return os;} template<class T>ostream&operator<<(ostream &os,const vector<T> &v){ ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;} //------------------------------------------------------------------------------ ll dp[50][5002]; int main_(int argc, char const *argv[]) { int N,A; cin>>N>>A; vector<int> x(N),y(N); REP(i,N) { cin>>x[i]; y[i]=x[i]-A; } FOR(i,0,N) { dp[i][2501+y[i]]++; REP(j,5002) { dp[i+1][j]+=dp[i][j]; if(0<=j+y[i+1] && j+y[i+1]<5000) dp[i+1][j+y[i+1]]+=dp[i][j]; } } cout<<dp[N-1][2501]<<endl; return 0; }
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s316448570
p04015
Java
public class Main { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); int A = 0; int N = 0; int[] X ; int result = 0; N = scanner.nextInt(); A = scanner.nextInt(); X = new int[N]; int pointer = 0; int way = 0; for (int i = 0; i < N; i++){ X[i] = scanner.nextInt(); } for(int i = 0; i < N ; i++ ){ int sum = 0; for(int j = 0; j < pointer; j++){ sum += X[j]; } for(int k = 0; k < N; k++){ if ( ((float)(sum + X[k])/(i+1)) == A){ way++; } } pointer ++; if(pointer >= 50){ break; } } System.out.print(way); } }
Main.java:2: error: cannot find symbol public static void main(String[] args) throws IOException { ^ symbol: class IOException location: class Main Main.java:3: error: cannot find symbol Scanner scanner = new Scanner(System.in); ^ symbol: class Scanner location: class Main Main.java:3: error: cannot find symbol Scanner scanner = new Scanner(System.in); ^ symbol: class Scanner location: class Main 3 errors
s499423559
p04015
C++
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i) #define rep(i,n) REP(i, 0, n) typedef long long int i64; typedef pair<int, int> pint; int main() { int N, A; cin >> N >> A; vector<int> X(N); rep(i, N) cin >> X[i]; vector<vector<i64>> dp(N + 1, vector<int>(2510, 0)); dp[0][0] = 1LL; rep(i, N) { auto dp_ = dp; int x = X[i]; rep(j, N) REP(k, x, 2510) { dp_[j + 1][k] += dp[j][k - x]; } dp = dp_; } i64 ans = 0LL; REP(i, 1, N + 1) ans += dp[i][i * A]; cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:13:55: error: no matching function for call to 'std::vector<std::vector<long long int> >::vector(int, std::vector<int>)' 13 | vector<vector<i64>> dp(N + 1, vector<int>(2510, 0)); | ^ In file included from /usr/include/c++/14/vector:66, from /usr/include/c++/14/functional:64, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53, from a.cc:1: /usr/include/c++/14/bits/stl_vector.h:707:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]' 707 | vector(_InputIterator __first, _InputIterator __last, | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:707:9: note: template argument deduction/substitution failed: a.cc:13:55: note: deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<int>') 13 | vector<vector<i64>> dp(N + 1, vector<int>(2510, 0)); | ^ /usr/include/c++/14/bits/stl_vector.h:678:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >]' 678 | vector(initializer_list<value_type> __l, | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:678:43: note: no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<long long int> >' 678 | vector(initializer_list<value_type> __l, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_vector.h:659:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::vector<long long int> >]' 659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:659:23: note: no known conversion for argument 1 from 'int' to 'std::vector<std::vector<long long int> >&&' 659 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) | ~~~~~~~~~^~~~ /usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >; std::false_type = std::false_type]' 640 | vector(vector&& __rv, const allocator_type& __m, false_type) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:640:7: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >; std::true_type = std::true_type]' 635 | vector(vector&& __rv, const allocator_type& __m, true_type) noexcept | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:635:7: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_vector.h:624:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; std::__type_identity_t<_Alloc> = std::allocator<std::vector<long long int> >]' 624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:624:28: note: no known conversion for argument 1 from 'int' to 'const std::vector<std::vector<long long int> >&' 624 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]' 620 | vector(vector&&) noexcept = default; | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:620:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]' 601 | vector(const vector& __x) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:601:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_vector.h:569:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; size_type = long unsigned int; value_type = std::vector<long long int>; allocator_type = std::allocator<std::vector<long long int> >]' 569 | vector(size_type __n, const value_type& __value, | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:569:47: note: no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<long long int> >::value_type&' {aka 'const std::vector<long long int>&'} 569 | vector(size_type __n, const value_type& __value, | ~~~~~~~~~~~~~~~~~~^~~~~~~ /usr/include/c++/14/bits/stl_vector.h:556:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; size_type = long unsigned int; allocator_type = std::allocator<std::vector<long long int> >]' 556 | vector(size_type __n, const allocator_type& __a = allocator_type()) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:556:51: note: no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<long long int> >::allocator_type&' {aka 'const std::allocator<std::vector<long long int> >&'} 556 | vector(size_type __n, const allocator_type& __a = allocator_type()) | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; allocator_type = std::allocator<std::vector<long long int> >]' 542 | vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:542:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]' 531 | vector() = default; | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:531:7: note: candidate expects 0 arguments, 2 provided
s670786756
p04015
C++
1
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 1 | ^
s493028299
p04015
Java
public class Main060 { public static void main(String[] args) { // キーボード入力をint配列へ詰める int intAry[] = new int[2]; Scanner in1 = new Scanner(System.in); for (int i = 0;i <= intAry.length; i++) { intAry[i] = in1.nextInt(); } in1.close(); // int intAry2[] = new int[intAry[0]]; Scanner in2 = new Scanner(System.in); for (int i = 0;i <= intAry2.length; i++) { intAry2[i] = in2.nextInt(); } in2.close(); // パターンカウント int result = 0; int sum = 0; int avg = 0; for (int c = 0; c <= intAry2.length; c++) { // average sum += intAry2[c]; avg = sum /intAry2.length; if (avg == intAry[1]) { result = result + 1; } if (intAry2[c] == intAry[1]) { result = result + 1; } } System.out.println(result); } }
Main.java:1: error: class Main060 is public, should be declared in a file named Main060.java public class Main060 { ^ Main.java:6: error: cannot find symbol Scanner in1 = new Scanner(System.in); ^ symbol: class Scanner location: class Main060 Main.java:6: error: cannot find symbol Scanner in1 = new Scanner(System.in); ^ symbol: class Scanner location: class Main060 Main.java:14: error: cannot find symbol Scanner in2 = new Scanner(System.in); ^ symbol: class Scanner location: class Main060 Main.java:14: error: cannot find symbol Scanner in2 = new Scanner(System.in); ^ symbol: class Scanner location: class Main060 5 errors
s014607420
p04015
C++
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int N = 55; int a,n; LL c[N][N*N]; int main(){ scanf("%d%d",&n,&a); c[0][0]=1; for(int i=1;i<=n;++i){ int x;scanf("%d",&x); for(int j=i;j>=1;--j){ for(int k=2500;k>=x;--k) c[j][k]+=c[j-1][k-x]; } } for(int i=1;i<=2500;++i){ for(int j=1;j<=n;++j)c[j][i]+=c[j][i-1]; } LL ret=0; for(int i=1;i<=n;++i){ int l=i*a; ret+=c[i][l]-c[i][l-1]; } cout<<ret<<endl; return 0; }
a.cc: In function 'int main()': a.cc:27:3: error: 'cout' was not declared in this scope 27 | cout<<ret<<endl; | ^~~~ a.cc:4:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>' 3 | #include <algorithm> +++ |+#include <iostream> 4 | using namespace std; a.cc:27:14: error: 'endl' was not declared in this scope 27 | cout<<ret<<endl; | ^~~~ a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>' 3 | #include <algorithm> +++ |+#include <ostream> 4 | using namespace std;
s895826742
p04015
C++
#include <iostream> #include <map> #include <vector> using namespace std; #define vvv vector<vector<vector<int > > > int main() { int N, A; cin >> N >> A; vector<int> x(N); for(int i = 0; i < N; ++i) cin >> x[i]; sort(x.begin(),x.end()); long long counter = 0; vector<vvv> subsetCount(N,vvv(50*50)); for(int i = 0; i < N; ++i) { if(i == 0) { for(int j = 0; j < N; ++j) subsetCount[0][ x[j] ].push_back({j}); } else { for(int j = 0; j < N; ++j) { for(int k = 0; k < 50*50; ++k) { //all sets that have k for(int l = 0; l < subsetCount[i-1][k].size(); ++l) { //set that has k bool isPresent = false; for(int m = 0; m < subsetCount[i-1][k][l].size() && isPresent == false; ++m) { if(subsetCount[i-1][k][l][m] >= j) isPresent = true; } if(isPresent == false) { subsetCount[i][k+x[j]].push_back(subsetCount[i-1][k][l]); subsetCount[i][k+x[j]].back().push_back(j); } } } } } //cout << (i+1) << " " << subsetCount[i][A*(i+1)].size() << endl; //cout << "---" << endl; //for(int l = 0; l < subsetCount[i][A*(i+1)].size(); ++l) { // for(auto it : subsetCount[i][A*(i+1)][l]) cout << it << " "; // cout << endl; //} counter += subsetCount[i][A*(i+1)].size(); } cout << counter << endl; }
a.cc: In function 'int main()': a.cc:11:5: error: 'sort' was not declared in this scope; did you mean 'short'? 11 | sort(x.begin(),x.end()); | ^~~~ | short
s309412612
p04015
C++
#include<iostream> #include<vector> #include<iomanip> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; using ulong = unsigned long; using ll = long long; int n, a; vector<int> xs; ll memo[51][51][2501]; ll solve(int idx, int cnt, int sum){ if(memo[idx][cnt][sum] != -1){ return memo[idx][cnt][sum]; } if(idx == n){ return sum && sum == cnt * a; } return memo[idx][cnt][sum] = solve(idx + 1, cnt, sum) + solve(idx + 1, cnt + 1, sum + xs[idx]); } ll ptrns[50][2501]; int main(){ cin >> n >> a; xs.resize(n); for(int i=0;i<n;i++){ cin >> xs[i]; } memset(memo, -1, sizeof(memo)); cout << solve(1, 0, 0) + solve(1, 1, xs[0]) << endl; return 0; }
a.cc: In function 'int main()': a.cc:33:9: error: 'memset' was not declared in this scope 33 | memset(memo, -1, sizeof(memo)); | ^~~~~~ a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 8 | #include<map> +++ |+#include <cstring> 9 | using namespace std;
s810215656
p04015
C++
import java.util.Scanner; public class Main { public static void main(String[] args){ try(Scanner scan = new Scanner(System.in)){ int N = scan.nextInt(); int A = scan.nextInt(); int[] x = new int[N]; long ans = 0; for(int i = 0; i<N; i++){ x[i] = scan.nextInt(); } double lim = Math.pow(2, N); for(long i = 0; i<lim; i++){ long set = i; int sum = 0; int cnt = 0; for(int j = 0; j<N; j++){ if((set & 1) > 0){ cnt++; sum+=x[j]; } set >>= 1; } double tmp = (double) sum/cnt; if(A - 0.0001 < tmp && tmp < A + 0.0001){ ans++; } } System.out.println(ans); } } }
a.cc:1:1: error: 'import' does not name a type 1 | import java.util.Scanner; | ^~~~~~ a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:3:1: error: expected unqualified-id before 'public' 3 | public class Main { | ^~~~~~
s836413410
p04015
C++
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> int main() { int n, a; int x[50]; long long total = 0; std::vector<std::vector<long long>> count, prev; std::cin >> n >> a; for (int ni = 0; ni < n; ++ni) { std::cin >> x[ni]; } count.resize(n + 1, std::vector<long long>(50 * n + 1, 0)); count[0][0] = 1; for (int ni = 0; ni < n; ++ni) { prev = count; for (int nj = 0; nj < n; ++nj) { for (int xi = 0; xi <= 50 * n; ++xi) { if (prev[nj][xi] > 0) { count[nj + 1][xi + x[ni]] += prev[nj][xi]; } } } } for (int ni = 1; ni <= n; ++ni) { total += count[ni][ni * a]; } std::cout << total << std::endl; return 0; } #include <algorithm> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> int main() { int n, a; int x[50]; long long total = 0; std::vector<std::vector<long long>> count, prev; std::cin >> n >> a; for (int ni = 0; ni < n; ++ni) { std::cin >> x[ni]; } count.resize(n + 1, std::vector<long long>(50 * n + 1, 0)); count[0][0] = 1; for (int ni = 0; ni < n; ++ni) { prev = count; for (int nj = 0; nj < n; ++nj) { for (int xi = 0; xi <= 50 * n; ++xi) { if (prev[nj][xi] > 0) { count[nj + 1][xi + x[ni]] += prev[nj][xi]; } } } } for (int ni = 1; ni <= n; ++ni) { total += count[ni][ni * a]; } std::cout << total << std::endl; return 0; }
a.cc:42:5: error: redefinition of 'int main()' 42 | int main() { | ^~~~ a.cc:8:5: note: 'int main()' previously defined here 8 | int main() { | ^~~~
s308252492
p04015
C++
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; unordered_map<int,int> a[26]; unordered_map<int,int> b[26]; int x[51]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, av; cin >> n >> av; for(int i = 0; i < n; i++) { cin >> x[i]; } int l = n/2; int r = n - l; for(int i = 0; i < (1<<l); i++) { //if(i%100000==0) cout << i << endl; int bit = __builtin_popcount(i); int sum = 0; for(int j = 0; j < l; j++) { if(i&(1<<j)) sum += x[j]; } a[bit][sum]++; } //cout << "PART 1 COMPLETE\n"; for(int i = 0; i < (1<<r); i++) { int bit = __builtin_popcount(i); int sum = 0; for(int j = 0; j < r; j++) { if(i&(1<<j)) sum += x[j+l]; } b[bit][sum]++; } //cout << "PART 2 COMPLETE\n"; ll ans = 0; for(int i = 0; i <= l; i++) { for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) { int sum = it->fi; //cout << sum << '\n'; for(int k = 0; k < 26; k++) { if(i + k == 0) continue; ans += it->se*b[k][av*(i+k) - sum]; } } } cout << ans; }
a.cc: In function 'int main()': a.cc:64:59: error: conversion from 'std::unordered_map<int, int>::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} to non-scalar type 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} requested 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ~~~~~~~~~~^~ a.cc:64:66: error: no match for 'operator!=' (operand types are 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} and 'std::unordered_map<int, int>::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'}) 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ~~ ^~ ~~~~~~~~~~ | | | | | std::unordered_map<int, int>::iterator {aka std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator} | std::map<int, int>::iterator {aka std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator} In file included from /usr/include/c++/14/regex:68, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181, from a.cc:1: /usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)' 1132 | operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1132:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)' 1212 | operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1212:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:1305:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)' 1305 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1305:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:1379:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)' 1379 | operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1379:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::unordered_map<int, int>::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)' 1473 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1473:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:1547:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)' 1547 | operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1547:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::unordered_map<int, int>::iterator' {aka 'std::__detail::_Insert_base<int, std::pair<const int, int>, std::allocator<std::pair<const int, int> >, std::__detail::_Select1st, std::equal_to<int>, std::hash<int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:1647:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)' 1647 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1647:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ /usr/include/c++/14/bits/regex.h:2213:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator!=(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)' 2213 | operator!=(const match_results<_Bi_iter, _Alloc>& __m1, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:2213:5: note: template argument deduction/substitution failed: a.cc:64:78: note: 'std::map<int, int>::iterator' {aka 'std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int> >, std::less<int>, std::allocator<std::pair<const int, int> > >::iterator'} is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>' 64 | for(map<int,int>::iterator it = a[i].begin(); it != a[i].end(); it++) | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class
s743693368
p04015
C++
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> int main() { int n, a; int x[50]; long long total = 0; std::vector<std::vector<int>> count, prev; std::cin >> n >> a; for (int ni = 0; ni < n; ++ni) { std::cin >> x[ni]; } count.resize(n + 1, std::vector<int>(50 * n + 1, 0)); count[0][0] = 1; for (int ni = 0; ni < n; ++ni) { prev = count; for (int nj = 0; nj < n; ++nj) { for (int xi = 0; xi <= 50 * n; ++xi) { if (prev[nj][xi] > 0) { count[nj + 1][xi + x[ni]] += prev[nj][xi]; } } } } for (int ni = 1; ni <= n; ++ni) { total += count[ni][ni * a]; } std::cout << total << std::endl; return 0; } #include <algorithm> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> int main() { int n, a; int x[50]; long long total = 0; std::vector<std::vector<int>> count, prev; std::cin >> n >> a; for (int ni = 0; ni < n; ++ni) { std::cin >> x[ni]; } count.resize(n + 1, std::vector<int>(50 * n + 1, 0)); count[0][0] = 1; for (int ni = 0; ni < n; ++ni) { prev = count; for (int nj = 0; nj < n; ++nj) { for (int xi = 0; xi <= 50 * n; ++xi) { if (prev[nj][xi] > 0) { count[nj + 1][xi + x[ni]] += prev[nj][xi]; } } } } for (int ni = 1; ni <= n; ++ni) { total += count[ni][ni * a]; } std::cout << total << std::endl; return 0; }
a.cc:42:5: error: redefinition of 'int main()' 42 | int main() { | ^~~~ a.cc:8:5: note: 'int main()' previously defined here 8 | int main() { | ^~~~
s414523157
p04015
C++
#include<bits/stdc++.h> //#pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <iostream> #include <iomanip> #include <fstream> #include <string.h> #include <stdlib.h> #include <time.h> #include <limits.h> #include <math.h> #include <algorithm> #include <deque> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <utility> #include <sstream> #include <complex> #include <string> #include <vector> #include <bitset> #include <functional> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef double db; typedef long double ldb; #define rep(i,a,b) for(i=a;i<b;i++) #define repu(i,a,b) for(i=a;i<=b;i++) #define repd(i,a,b) for(i=a;i>=b;i--) #define repc(i,a,b,c) for(i=a;i<b;i+=c) #define repcu(i,a,b,c) for(i=a;i<=b;i+=c) #define repcd(i,a,b,c) for(i=a;i>=b;i-=c) #define FIN freopen("input.in","r",stdin) #define FOUT freopen("output.out","w",stdout) #define CC(a) memset(a,0,sizeof(a)) #define MST(a,b) memset(a,b,sizeof(a)) #define PII pair<int,int> #define PLL pair<long long,long long> #define VI vector<int> #define VL vector<long long> #define VII vector<PII> #define VLL vector<PLL> #define all(x) x.begin(),x.end() #define mp make_pair #define pb push_back #define pf push_front template<typename T>inline void gn(T &x){ x=0;T f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();} x*=f; } template<typename T>inline void gt(T x){ if(!x)return; gt(x/10);putchar(x%10+'0'); } const LL N=1e6+5; struct NODE{ LL i,r,c,num; }tt,ss; LL n,m,q; LL MOD=1e9+7,inf=0x1f1f1f1f; db eps=1e-5; map<LL,LL> ma; int main() { // ios_base::sync_with_stdio(false);cin.tie(0); LL i,j,k,l,ca=0,u,v,tmp; cin>>n>>m; repu(i,1,n){ cin>>t; ma[t]++; } rep(i,1,m){ ans+=max(ma[m-i],ma[m+i]); } cout<<ans+ma[m]<<endl; return 0; }
a.cc: In function 'int main()': a.cc:78:22: error: 't' was not declared in this scope 78 | cin>>t; | ^ a.cc:82:17: error: 'ans' was not declared in this scope; did you mean 'abs'? 82 | ans+=max(ma[m-i],ma[m+i]); | ^~~ | abs a.cc:84:15: error: 'ans' was not declared in this scope; did you mean 'abs'? 84 | cout<<ans+ma[m]<<endl; | ^~~ | abs
s128713078
p04016
C++
#ifndef ATCODER_INTERNAL_BITOP_HPP #define ATCODER_INTERNAL_BITOP_HPP 1 #ifdef _MSC_VER #include <intrin.h> #endif namespace atcoder { namespace internal { // @param n `0 <= n` // @return minimum non-negative `x` s.t. `n <= 2**x` int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } // @param n `1 <= n` // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0` int bsf(unsigned int n) { #ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index; #else return __builtin_ctz(n); #endif } } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_BITOP_HPP #ifndef ATCODER_INTERNAL_MATH_HPP #define ATCODER_INTERNAL_MATH_HPP 1 #include <utility> namespace atcoder { namespace internal { // @param m `1 <= m` // @return x mod m constexpr long long safe_mod(long long x, long long m) { x %= m; if (x < 0) x += m; return x; } // Fast moduler by barrett reduction // Reference: https://en.wikipedia.org/wiki/Barrett_reduction // NOTE: reconsider after Ice Lake struct barrett { unsigned int _m; unsigned long long im; // @param m `1 <= m` barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {} // @return m unsigned int umod() const { return _m; } // @param a `0 <= a < m` // @param b `0 <= b < m` // @return `a * b % m` unsigned int mul(unsigned int a, unsigned int b) const { // [1] m = 1 // a = b = im = 0, so okay // [2] m >= 2 // im = ceil(2^64 / m) // -> im * m = 2^64 + r (0 <= r < m) // let z = a*b = c*m + d (0 <= c, d < m) // a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im // c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2 // ((ab * im) >> 64) == c or c + 1 unsigned long long z = a; z *= b; #ifdef _MSC_VER unsigned long long x; _umul128(z, im, &x); #else unsigned long long x = (unsigned long long)(((unsigned __int128)(z)*im) >> 64); #endif unsigned int v = (unsigned int)(z - x * _m); if (_m <= v) v += _m; return v; } }; // @param n `0 <= n` // @param m `1 <= m` // @return `(x ** n) % m` constexpr long long pow_mod_constexpr(long long x, long long n, int m) { if (m == 1) return 0; unsigned int _m = (unsigned int)(m); unsigned long long r = 1; unsigned long long y = safe_mod(x, m); while (n) { if (n & 1) r = (r * y) % _m; y = (y * y) % _m; n >>= 1; } return r; } // Reference: // M. Forisek and J. Jancina, // Fast Primality Testing for Integers That Fit into a Machine Word // @param n `0 <= n` constexpr bool is_prime_constexpr(int n) { if (n <= 1) return false; if (n == 2 || n == 7 || n == 61) return true; if (n % 2 == 0) return false; long long d = n - 1; while (d % 2 == 0) d /= 2; for (long long a : {2, 7, 61}) { long long t = d; long long y = pow_mod_constexpr(a, t, n); while (t != n - 1 && y != 1 && y != n - 1) { y = y * y % n; t <<= 1; } if (y != n - 1 && t % 2 == 0) { return false; } } return true; } template <int n> constexpr bool is_prime = is_prime_constexpr(n); // @param b `1 <= b` // @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) { a = safe_mod(a, b); if (a == 0) return {b, 0}; // Contracts: // [1] s - m0 * a = 0 (mod b) // [2] t - m1 * a = 0 (mod b) // [3] s * |m1| + t * |m0| <= b long long s = b, t = a; long long m0 = 0, m1 = 1; while (t) { long long u = s / t; s -= t * u; m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b // [3]: // (s - t * u) * |m1| + t * |m0 - m1 * u| // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u) // = s * |m1| + t * |m0| <= b auto tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } // by [3]: |m0| <= b/g // by g != b: |m0| < b/g if (m0 < 0) m0 += b / s; return {s, m0}; } // Compile time primitive root // @param m must be prime // @return primitive root (and minimum in now) constexpr int primitive_root_constexpr(int m) { if (m == 2) return 1; if (m == 167772161) return 3; if (m == 469762049) return 3; if (m == 754974721) return 11; if (m == 998244353) return 3; int divs[20] = {}; divs[0] = 2; int cnt = 1; int x = (m - 1) / 2; while (x % 2 == 0) x /= 2; for (int i = 3; (long long)(i)*i <= x; i += 2) { if (x % i == 0) { divs[cnt++] = i; while (x % i == 0) { x /= i; } } } if (x > 1) { divs[cnt++] = x; } for (int g = 2;; g++) { bool ok = true; for (int i = 0; i < cnt; i++) { if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) { ok = false; break; } } if (ok) return g; } } template <int m> constexpr int primitive_root = primitive_root_constexpr(m); } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_MATH_HPP #ifndef ATCODER_INTERNAL_QUEUE_HPP #define ATCODER_INTERNAL_QUEUE_HPP 1 #include <vector> namespace atcoder { namespace internal { template <class T> struct simple_queue { std::vector<T> payload; int pos = 0; void reserve(int n) { payload.reserve(n); } int size() const { return int(payload.size()) - pos; } bool empty() const { return pos == int(payload.size()); } void push(const T& t) { payload.push_back(t); } T& front() { return payload[pos]; } void clear() { payload.clear(); pos = 0; } void pop() { pos++; } }; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_QUEUE_HPP #ifndef ATCODER_INTERNAL_SCC_HPP #define ATCODER_INTERNAL_SCC_HPP 1 #include <algorithm> #include <utility> #include <vector> namespace atcoder { namespace internal { template <class E> struct csr { std::vector<int> start; std::vector<E> elist; csr(int n, const std::vector<std::pair<int, E>>& edges) : start(n + 1), elist(edges.size()) { for (auto e : edges) { start[e.first + 1]++; } for (int i = 1; i <= n; i++) { start[i] += start[i - 1]; } auto counter = start; for (auto e : edges) { elist[counter[e.first]++] = e.second; } } }; // Reference: // R. Tarjan, // Depth-First Search and Linear Graph Algorithms struct scc_graph { public: scc_graph(int n) : _n(n) {} int num_vertices() { return _n; } void add_edge(int from, int to) { edges.push_back({from, {to}}); } // @return pair of (# of scc, scc id) std::pair<int, std::vector<int>> scc_ids() { auto g = csr<edge>(_n, edges); int now_ord = 0, group_num = 0; std::vector<int> visited, low(_n), ord(_n, -1), ids(_n); visited.reserve(_n); auto dfs = [&](auto self, int v) -> void { low[v] = ord[v] = now_ord++; visited.push_back(v); for (int i = g.start[v]; i < g.start[v + 1]; i++) { auto to = g.elist[i].to; if (ord[to] == -1) { self(self, to); low[v] = std::min(low[v], low[to]); } else { low[v] = std::min(low[v], ord[to]); } } if (low[v] == ord[v]) { while (true) { int u = visited.back(); visited.pop_back(); ord[u] = _n; ids[u] = group_num; if (u == v) break; } group_num++; } }; for (int i = 0; i < _n; i++) { if (ord[i] == -1) dfs(dfs, i); } for (auto& x : ids) { x = group_num - 1 - x; } return {group_num, ids}; } std::vector<std::vector<int>> scc() { auto ids = scc_ids(); int group_num = ids.first; std::vector<int> counts(group_num); for (auto x : ids.second) counts[x]++; std::vector<std::vector<int>> groups(ids.first); for (int i = 0; i < group_num; i++) { groups[i].reserve(counts[i]); } for (int i = 0; i < _n; i++) { groups[ids.second[i]].push_back(i); } return groups; } private: int _n; struct edge { int to; }; std::vector<std::pair<int, edge>> edges; }; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_SCC_HPP #ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP #define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1 #include <cassert> #include <numeric> #include <type_traits> namespace atcoder { namespace internal { #ifndef _MSC_VER template <class T> using is_signed_int128 = typename std::conditional<std::is_same<T, __int128_t>::value || std::is_same<T, __int128>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int128 = typename std::conditional<std::is_same<T, __uint128_t>::value || std::is_same<T, unsigned __int128>::value, std::true_type, std::false_type>::type; template <class T> using make_unsigned_int128 = typename std::conditional<std::is_same<T, __int128_t>::value, __uint128_t, unsigned __int128>; template <class T> using is_integral = typename std::conditional<std::is_integral<T>::value || is_signed_int128<T>::value || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_signed_int = typename std::conditional<(is_integral<T>::value && std::is_signed<T>::value) || is_signed_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<(is_integral<T>::value && std::is_unsigned<T>::value) || is_unsigned_int128<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional< is_signed_int128<T>::value, make_unsigned_int128<T>, typename std::conditional<std::is_signed<T>::value, std::make_unsigned<T>, std::common_type<T>>::type>::type; #else template <class T> using is_integral = typename std::is_integral<T>; template <class T> using is_signed_int = typename std::conditional<is_integral<T>::value && std::is_signed<T>::value, std::true_type, std::false_type>::type; template <class T> using is_unsigned_int = typename std::conditional<is_integral<T>::value && std::is_unsigned<T>::value, std::true_type, std::false_type>::type; template <class T> using to_unsigned = typename std::conditional<is_signed_int<T>::value, std::make_unsigned<T>, std::common_type<T>>::type; #endif template <class T> using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>; template <class T> using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>; template <class T> using to_unsigned_t = typename to_unsigned<T>::type; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_TYPE_TRAITS_HPP #ifndef ATCODER_MODINT_HPP #define ATCODER_MODINT_HPP 1 #include <cassert> #include <numeric> #include <type_traits> #ifdef _MSC_VER #include <intrin.h> #endif namespace atcoder { namespace internal { struct modint_base {}; struct static_modint_base : modint_base {}; template <class T> using is_modint = std::is_base_of<modint_base, T>; template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>; } // namespace internal template <int m, std::enable_if_t<(1 <= m)>* = nullptr> struct static_modint : internal::static_modint_base { using mint = static_modint; public: static constexpr int mod() { return m; } static mint raw(int v) { mint x; x._v = v; return x; } static_modint() : _v(0) {} template <class T, internal::is_signed_int_t<T>* = nullptr> static_modint(T v) { long long x = (long long)(v % (long long)(umod())); if (x < 0) x += umod(); _v = (unsigned int)(x); } template <class T, internal::is_unsigned_int_t<T>* = nullptr> static_modint(T v) { _v = (unsigned int)(v % umod()); } static_modint(bool v) { _v = ((unsigned int)(v) % umod()); } unsigned int val() const { return _v; } mint& operator++() { _v++; if (_v == umod()) _v = 0; return *this; } mint& operator--() { if (_v == 0) _v = umod(); _v--; return *this; } mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint& operator+=(const mint& rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } mint& operator-=(const mint& rhs) { _v -= rhs._v; if (_v >= umod()) _v += umod(); return *this; } mint& operator*=(const mint& rhs) { unsigned long long z = _v; z *= rhs._v; _v = (unsigned int)(z % umod()); return *this; } mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); mint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { if (prime) { assert(_v); return pow(umod() - 2); } else { auto eg = internal::inv_gcd(_v, m); assert(eg.first == 1); return eg.second; } } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return lhs._v == rhs._v; } friend bool operator!=(const mint& lhs, const mint& rhs) { return lhs._v != rhs._v; } private: unsigned int _v; static constexpr unsigned int umod() { return m; } static constexpr bool prime = internal::is_prime<m>; }; template <int id> struct dynamic_modint : internal::modint_base { using mint = dynamic_modint; public: static int mod() { return (int)(bt.umod()); } static void set_mod(int m) { assert(1 <= m); bt = internal::barrett(m); } static mint raw(int v) { mint x; x._v = v; return x; } dynamic_modint() : _v(0) {} template <class T, internal::is_signed_int_t<T>* = nullptr> dynamic_modint(T v) { long long x = (long long)(v % (long long)(mod())); if (x < 0) x += mod(); _v = (unsigned int)(x); } template <class T, internal::is_unsigned_int_t<T>* = nullptr> dynamic_modint(T v) { _v = (unsigned int)(v % mod()); } dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); } unsigned int val() const { return _v; } mint& operator++() { _v++; if (_v == umod()) _v = 0; return *this; } mint& operator--() { if (_v == 0) _v = umod(); _v--; return *this; } mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint& operator+=(const mint& rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } mint& operator-=(const mint& rhs) { _v += mod() - rhs._v; if (_v >= umod()) _v -= umod(); return *this; } mint& operator*=(const mint& rhs) { _v = bt.mul(_v, rhs._v); return *this; } mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); mint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { auto eg = internal::inv_gcd(_v, mod()); assert(eg.first == 1); return eg.second; } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return lhs._v == rhs._v; } friend bool operator!=(const mint& lhs, const mint& rhs) { return lhs._v != rhs._v; } private: unsigned int _v; static internal::barrett bt; static unsigned int umod() { return bt.umod(); } }; template <int id> internal::barrett dynamic_modint<id>::bt = 998244353; using modint998244353 = static_modint<998244353>; using modint1000000007 = static_modint<1000000007>; using modint = dynamic_modint<-1>; namespace internal { template <class T> using is_static_modint = std::is_base_of<internal::static_modint_base, T>; template <class T> using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>; template <class> struct is_dynamic_modint : public std::false_type {}; template <int id> struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {}; template <class T> using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>; } // namespace internal } // namespace atcoder #endif // ATCODER_MODINT_HPP #ifndef ATCODER_CONVOLUTION_HPP #define ATCODER_CONVOLUTION_HPP 1 #include <algorithm> #include <array> #include <cassert> #include <type_traits> #include <vector> namespace atcoder { namespace internal { template <class mint, internal::is_static_modint_t<mint>* = nullptr> void butterfly(std::vector<mint>& a) { static constexpr int g = internal::primitive_root<mint::mod()>; int n = int(a.size()); int h = internal::ceil_pow2(n); static bool first = true; static mint sum_e[30]; // sum_e[i] = ies[0] * ... * ies[i - 1] * es[i] if (first) { first = false; mint es[30], ies[30]; // es[i]^(2^(2+i)) == 1 int cnt2 = bsf(mint::mod() - 1); mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv(); for (int i = cnt2; i >= 2; i--) { // e^(2^i) == 1 es[i - 2] = e; ies[i - 2] = ie; e *= e; ie *= ie; } mint now = 1; for (int i = 0; i <= cnt2 - 2; i++) { sum_e[i] = es[i] * now; now *= ies[i]; } } for (int ph = 1; ph <= h; ph++) { int w = 1 << (ph - 1), p = 1 << (h - ph); mint now = 1; for (int s = 0; s < w; s++) { int offset = s << (h - ph + 1); for (int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p] * now; a[i + offset] = l + r; a[i + offset + p] = l - r; } now *= sum_e[bsf(~(unsigned int)(s))]; } } } template <class mint, internal::is_static_modint_t<mint>* = nullptr> void butterfly_inv(std::vector<mint>& a) { static constexpr int g = internal::primitive_root<mint::mod()>; int n = int(a.size()); int h = internal::ceil_pow2(n); static bool first = true; static mint sum_ie[30]; // sum_ie[i] = es[0] * ... * es[i - 1] * ies[i] if (first) { first = false; mint es[30], ies[30]; // es[i]^(2^(2+i)) == 1 int cnt2 = bsf(mint::mod() - 1); mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv(); for (int i = cnt2; i >= 2; i--) { // e^(2^i) == 1 es[i - 2] = e; ies[i - 2] = ie; e *= e; ie *= ie; } mint now = 1; for (int i = 0; i <= cnt2 - 2; i++) { sum_ie[i] = ies[i] * now; now *= es[i]; } } for (int ph = h; ph >= 1; ph--) { int w = 1 << (ph - 1), p = 1 << (h - ph); mint inow = 1; for (int s = 0; s < w; s++) { int offset = s << (h - ph + 1); for (int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p]; a[i + offset] = l + r; a[i + offset + p] = (unsigned long long)(mint::mod() + l.val() - r.val()) * inow.val(); } inow *= sum_ie[bsf(~(unsigned int)(s))]; } } } } // namespace internal template <class mint, internal::is_static_modint_t<mint>* = nullptr> std::vector<mint> convolution(std::vector<mint> a, std::vector<mint> b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; if (std::min(n, m) <= 60) { if (n < m) { std::swap(n, m); std::swap(a, b); } std::vector<mint> ans(n + m - 1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans[i + j] += a[i] * b[j]; } } return ans; } int z = 1 << internal::ceil_pow2(n + m - 1); a.resize(z); internal::butterfly(a); b.resize(z); internal::butterfly(b); for (int i = 0; i < z; i++) { a[i] *= b[i]; } internal::butterfly_inv(a); a.resize(n + m - 1); mint iz = mint(z).inv(); for (int i = 0; i < n + m - 1; i++) a[i] *= iz; return a; } template <unsigned int mod = 998244353, class T, std::enable_if_t<internal::is_integral<T>::value>* = nullptr> std::vector<T> convolution(const std::vector<T>& a, const std::vector<T>& b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; using mint = static_modint<mod>; std::vector<mint> a2(n), b2(m); for (int i = 0; i < n; i++) { a2[i] = mint(a[i]); } for (int i = 0; i < m; i++) { b2[i] = mint(b[i]); } auto c2 = convolution(move(a2), move(b2)); std::vector<T> c(n + m - 1); for (int i = 0; i < n + m - 1; i++) { c[i] = c2[i].val(); } return c; } std::vector<long long> convolution_ll(const std::vector<long long>& a, const std::vector<long long>& b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; static constexpr unsigned long long MOD1 = 754974721; // 2^24 static constexpr unsigned long long MOD2 = 167772161; // 2^25 static constexpr unsigned long long MOD3 = 469762049; // 2^26 static constexpr unsigned long long M2M3 = MOD2 * MOD3; static constexpr unsigned long long M1M3 = MOD1 * MOD3; static constexpr unsigned long long M1M2 = MOD1 * MOD2; static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3; static constexpr unsigned long long i1 = internal::inv_gcd(MOD2 * MOD3, MOD1).second; static constexpr unsigned long long i2 = internal::inv_gcd(MOD1 * MOD3, MOD2).second; static constexpr unsigned long long i3 = internal::inv_gcd(MOD1 * MOD2, MOD3).second; auto c1 = convolution<MOD1>(a, b); auto c2 = convolution<MOD2>(a, b); auto c3 = convolution<MOD3>(a, b); std::vector<long long> c(n + m - 1); for (int i = 0; i < n + m - 1; i++) { unsigned long long x = 0; x += (c1[i] * i1) % MOD1 * M2M3; x += (c2[i] * i2) % MOD2 * M1M3; x += (c3[i] * i3) % MOD3 * M1M2; // B = 2^63, -B <= x, r(real value) < B // (x, x - M, x - 2M, or x - 3M) = r (mod 2B) // r = c1[i] (mod MOD1) // focus on MOD1 // r = x, x - M', x - 2M', x - 3M' (M' = M % 2^64) (mod 2B) // r = x, // x - M' + (0 or 2B), // x - 2M' + (0, 2B or 4B), // x - 3M' + (0, 2B, 4B or 6B) (without mod!) // (r - x) = 0, (0) // - M' + (0 or 2B), (1) // -2M' + (0 or 2B or 4B), (2) // -3M' + (0 or 2B or 4B or 6B) (3) (mod MOD1) // we checked that // ((1) mod MOD1) mod 5 = 2 // ((2) mod MOD1) mod 5 = 3 // ((3) mod MOD1) mod 5 = 4 long long diff = c1[i] - internal::safe_mod((long long)(x), (long long)(MOD1)); if (diff < 0) diff += MOD1; static constexpr unsigned long long offset[5] = { 0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3}; x -= offset[diff % 5]; c[i] = x; } return c; } } // namespace atcoder #endif // ATCODER_CONVOLUTION_HPP #ifndef ATCODER_DSU_HPP #define ATCODER_DSU_HPP 1 #include <algorithm> #include <cassert> #include <vector> namespace atcoder { // Implement (union by size) + (path compression) // Reference: // Zvi Galil and Giuseppe F. Italiano, // Data structures and algorithms for disjoint set union problems struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; } // namespace atcoder #endif // ATCODER_DSU_HPP #ifndef ATCODER_FENWICKTREE_HPP #define ATCODER_FENWICKTREE_HPP 1 #include <cassert> #include <vector> namespace atcoder { // Reference: https://en.wikipedia.org/wiki/Fenwick_tree template <class T> struct fenwick_tree { using U = internal::to_unsigned_t<T>; public: fenwick_tree() : _n(0) {} fenwick_tree(int n) : _n(n), data(n) {} void add(int p, T x) { assert(0 <= p && p < _n); p++; while (p <= _n) { data[p - 1] += U(x); p += p & -p; } } T sum(int l, int r) { assert(0 <= l && l <= r && r <= _n); return sum(r) - sum(l); } private: int _n; std::vector<U> data; U sum(int r) { U s = 0; while (r > 0) { s += data[r - 1]; r -= r & -r; } return s; } }; } // namespace atcoder #endif // ATCODER_FENWICKTREE_HPP #ifndef ATCODER_LAZYSEGTREE_HPP #define ATCODER_LAZYSEGTREE_HPP 1 #include <algorithm> #include <cassert> #include <iostream> #include <vector> namespace atcoder { template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()> struct lazy_segtree { public: lazy_segtree() : lazy_segtree(0) {} lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {} lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) { log = internal::ceil_pow2(_n); size = 1 << log; d = std::vector<S>(2 * size, e()); lz = std::vector<F>(size, id()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); return d[p]; } S prod(int l, int r) { assert(0 <= l && l <= r && r <= _n); if (l == r) return e(); l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push(r >> i); } S sml = e(), smr = e(); while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } void apply(int p, F f) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = mapping(f, d[p]); for (int i = 1; i <= log; i++) update(p >> i); } void apply(int l, int r, F f) { assert(0 <= l && l <= r && r <= _n); if (l == r) return; l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } template <bool (*g)(S)> int max_right(int l) { return max_right(l, [](S x) { return g(x); }); } template <class G> int max_right(int l, G g) { assert(0 <= l && l <= _n); assert(g(e())); if (l == _n) return _n; l += size; for (int i = log; i >= 1; i--) push(l >> i); S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, d[l]))) { while (l < size) { push(l); l = (2 * l); if (g(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*g)(S)> int min_left(int r) { return min_left(r, [](S x) { return g(x); }); } template <class G> int min_left(int r, G g) { assert(0 <= r && r <= _n); assert(g(e())); if (r == 0) return 0; r += size; for (int i = log; i >= 1; i--) push((r - 1) >> i); S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!g(op(d[r], sm))) { while (r < size) { push(r); r = (2 * r + 1); if (g(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector<S> d; std::vector<F> lz; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } void all_apply(int k, F f) { d[k] = mapping(f, d[k]); if (k < size) lz[k] = composition(f, lz[k]); } void push(int k) { all_apply(2 * k, lz[k]); all_apply(2 * k + 1, lz[k]); lz[k] = id(); } }; } // namespace atcoder #endif // ATCODER_LAZYSEGTREE_HPP #ifndef ATCODER_MATH_HPP #define ATCODER_MATH_HPP 1 #include <algorithm> #include <cassert> #include <tuple> #include <vector> namespace atcoder { long long pow_mod(long long x, long long n, int m) { assert(0 <= n && 1 <= m); if (m == 1) return 0; internal::barrett bt((unsigned int)(m)); unsigned int r = 1, y = (unsigned int)(internal::safe_mod(x, m)); while (n) { if (n & 1) r = bt.mul(r, y); y = bt.mul(y, y); n >>= 1; } return r; } long long inv_mod(long long x, long long m) { assert(1 <= m); auto z = internal::inv_gcd(x, m); assert(z.first == 1); return z.second; } // (rem, mod) std::pair<long long, long long> crt(const std::vector<long long>& r, const std::vector<long long>& m) { assert(r.size() == m.size()); int n = int(r.size()); // Contracts: 0 <= r0 < m0 long long r0 = 0, m0 = 1; for (int i = 0; i < n; i++) { assert(1 <= m[i]); long long r1 = internal::safe_mod(r[i], m[i]), m1 = m[i]; if (m0 < m1) { std::swap(r0, r1); std::swap(m0, m1); } if (m0 % m1 == 0) { if (r0 % m1 != r1) return {0, 0}; continue; } // assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1) // (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1)); // r2 % m0 = r0 // r2 % m1 = r1 // -> (r0 + x*m0) % m1 = r1 // -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1) // -> x = (r1 - r0) / g * inv(u0) (mod u1) // im = inv(u0) (mod u1) (0 <= im < u1) long long g, im; std::tie(g, im) = internal::inv_gcd(m0, m1); long long u1 = (m1 / g); // |r1 - r0| < (m0 + m1) <= lcm(m0, m1) if ((r1 - r0) % g) return {0, 0}; // u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1) long long x = (r1 - r0) / g % u1 * im % u1; // |r0| + |m0 * x| // < m0 + m0 * (u1 - 1) // = m0 + m0 * m1 / g - m0 // = lcm(m0, m1) r0 += x * m0; m0 *= u1; // -> lcm(m0, m1) if (r0 < 0) r0 += m0; } return {r0, m0}; } long long floor_sum(long long n, long long m, long long a, long long b) { long long ans = 0; if (a >= m) { ans += (n - 1) * n * (a / m) / 2; a %= m; } if (b >= m) { ans += n * (b / m); b %= m; } long long y_max = (a * n + b) / m, x_max = (y_max * m - b); if (y_max == 0) return ans; ans += (n - (x_max + a - 1) / a) * y_max; ans += floor_sum(y_max, a, m, (a - x_max % a) % a); return ans; } } // namespace atcoder #endif // ATCODER_MATH_HPP #ifndef ATCODER_MAXFLOW_HPP #define ATCODER_MAXFLOW_HPP 1 #include <algorithm> #include <cassert> #include <limits> #include <queue> #include <vector> namespace atcoder { template <class Cap> struct mf_graph { public: mf_graph() : _n(0) {} mf_graph(int n) : _n(n), g(n) {} int add_edge(int from, int to, Cap cap) { assert(0 <= from && from < _n); assert(0 <= to && to < _n); assert(0 <= cap); int m = int(pos.size()); pos.push_back({from, int(g[from].size())}); g[from].push_back(_edge{to, int(g[to].size()), cap}); g[to].push_back(_edge{from, int(g[from].size()) - 1, 0}); return m; } struct edge { int from, to; Cap cap, flow; }; edge get_edge(int i) { int m = int(pos.size()); assert(0 <= i && i < m); auto _e = g[pos[i].first][pos[i].second]; auto _re = g[_e.to][_e.rev]; return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap}; } std::vector<edge> edges() { int m = int(pos.size()); std::vector<edge> result; for (int i = 0; i < m; i++) { result.push_back(get_edge(i)); } return result; } void change_edge(int i, Cap new_cap, Cap new_flow) { int m = int(pos.size()); assert(0 <= i && i < m); assert(0 <= new_flow && new_flow <= new_cap); auto& _e = g[pos[i].first][pos[i].second]; auto& _re = g[_e.to][_e.rev]; _e.cap = new_cap - new_flow; _re.cap = new_flow; } Cap flow(int s, int t) { return flow(s, t, std::numeric_limits<Cap>::max()); } Cap flow(int s, int t, Cap flow_limit) { assert(0 <= s && s < _n); assert(0 <= t && t < _n); std::vector<int> level(_n), iter(_n); internal::simple_queue<int> que; auto bfs = [&]() { std::fill(level.begin(), level.end(), -1); level[s] = 0; que.clear(); que.push(s); while (!que.empty()) { int v = que.front(); que.pop(); for (auto e : g[v]) { if (e.cap == 0 || level[e.to] >= 0) continue; level[e.to] = level[v] + 1; if (e.to == t) return; que.push(e.to); } } }; auto dfs = [&](auto self, int v, Cap up) { if (v == s) return up; Cap res = 0; int level_v = level[v]; for (int& i = iter[v]; i < int(g[v].size()); i++) { _edge& e = g[v][i]; if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue; Cap d = self(self, e.to, std::min(up - res, g[e.to][e.rev].cap)); if (d <= 0) continue; g[v][i].cap += d; g[e.to][e.rev].cap -= d; res += d; if (res == up) break; } return res; }; Cap flow = 0; while (flow < flow_limit) { bfs(); if (level[t] == -1) break; std::fill(iter.begin(), iter.end(), 0); while (flow < flow_limit) { Cap f = dfs(dfs, t, flow_limit - flow); if (!f) break; flow += f; } } return flow; } std::vector<bool> min_cut(int s) { std::vector<bool> visited(_n); internal::simple_queue<int> que; que.push(s); while (!que.empty()) { int p = que.front(); que.pop(); visited[p] = true; for (auto e : g[p]) { if (e.cap && !visited[e.to]) { visited[e.to] = true; que.push(e.to); } } } return visited; } private: int _n; struct _edge { int to, rev; Cap cap; }; std::vector<std::pair<int, int>> pos; std::vector<std::vector<_edge>> g; }; } // namespace atcoder #endif // ATCODER_MAXFLOW_HPP #ifndef ATCODER_MINCOSTFLOW_HPP #define ATCODER_MINCOSTFLOW_HPP 1 #include <algorithm> #include <cassert> #include <limits> #include <queue> #include <vector> namespace atcoder { template <class Cap, class Cost> struct mcf_graph { public: mcf_graph() {} mcf_graph(int n) : _n(n), g(n) {} int add_edge(int from, int to, Cap cap, Cost cost) { assert(0 <= from && from < _n); assert(0 <= to && to < _n); int m = int(pos.size()); pos.push_back({from, int(g[from].size())}); g[from].push_back(_edge{to, int(g[to].size()), cap, cost}); g[to].push_back(_edge{from, int(g[from].size()) - 1, 0, -cost}); return m; } struct edge { int from, to; Cap cap, flow; Cost cost; }; edge get_edge(int i) { int m = int(pos.size()); assert(0 <= i && i < m); auto _e = g[pos[i].first][pos[i].second]; auto _re = g[_e.to][_e.rev]; return edge{ pos[i].first, _e.to, _e.cap + _re.cap, _re.cap, _e.cost, }; } std::vector<edge> edges() { int m = int(pos.size()); std::vector<edge> result(m); for (int i = 0; i < m; i++) { result[i] = get_edge(i); } return result; } std::pair<Cap, Cost> flow(int s, int t) { return flow(s, t, std::numeric_limits<Cap>::max()); } std::pair<Cap, Cost> flow(int s, int t, Cap flow_limit) { return slope(s, t, flow_limit).back(); } std::vector<std::pair<Cap, Cost>> slope(int s, int t) { return slope(s, t, std::numeric_limits<Cap>::max()); } std::vector<std::pair<Cap, Cost>> slope(int s, int t, Cap flow_limit) { assert(0 <= s && s < _n); assert(0 <= t && t < _n); assert(s != t); // variants (C = maxcost): // -(n-1)C <= dual[s] <= dual[i] <= dual[t] = 0 // reduced cost (= e.cost + dual[e.from] - dual[e.to]) >= 0 for all edge std::vector<Cost> dual(_n, 0), dist(_n); std::vector<int> pv(_n), pe(_n); std::vector<bool> vis(_n); auto dual_ref = [&]() { std::fill(dist.begin(), dist.end(), std::numeric_limits<Cost>::max()); std::fill(pv.begin(), pv.end(), -1); std::fill(pe.begin(), pe.end(), -1); std::fill(vis.begin(), vis.end(), false); struct Q { Cost key; int to; bool operator<(Q r) const { return key > r.key; } }; std::priority_queue<Q> que; dist[s] = 0; que.push(Q{0, s}); while (!que.empty()) { int v = que.top().to; que.pop(); if (vis[v]) continue; vis[v] = true; if (v == t) break; // dist[v] = shortest(s, v) + dual[s] - dual[v] // dist[v] >= 0 (all reduced cost are positive) // dist[v] <= (n-1)C for (int i = 0; i < int(g[v].size()); i++) { auto e = g[v][i]; if (vis[e.to] || !e.cap) continue; // |-dual[e.to] + dual[v]| <= (n-1)C // cost <= C - -(n-1)C + 0 = nC Cost cost = e.cost - dual[e.to] + dual[v]; if (dist[e.to] - dist[v] > cost) { dist[e.to] = dist[v] + cost; pv[e.to] = v; pe[e.to] = i; que.push(Q{dist[e.to], e.to}); } } } if (!vis[t]) { return false; } for (int v = 0; v < _n; v++) { if (!vis[v]) continue; // dual[v] = dual[v] - dist[t] + dist[v] // = dual[v] - (shortest(s, t) + dual[s] - dual[t]) + (shortest(s, v) + dual[s] - dual[v]) // = - shortest(s, t) + dual[t] + shortest(s, v) // = shortest(s, v) - shortest(s, t) >= 0 - (n-1)C dual[v] -= dist[t] - dist[v]; } return true; }; Cap flow = 0; Cost cost = 0, prev_cost = -1; std::vector<std::pair<Cap, Cost>> result; result.push_back({flow, cost}); while (flow < flow_limit) { if (!dual_ref()) break; Cap c = flow_limit - flow; for (int v = t; v != s; v = pv[v]) { c = std::min(c, g[pv[v]][pe[v]].cap); } for (int v = t; v != s; v = pv[v]) { auto& e = g[pv[v]][pe[v]]; e.cap -= c; g[v][e.rev].cap += c; } Cost d = -dual[s]; flow += c; cost += c * d; if (prev_cost == d) { result.pop_back(); } result.push_back({flow, cost}); prev_cost = cost; } return result; } private: int _n; struct _edge { int to, rev; Cap cap; Cost cost; }; std::vector<std::pair<int, int>> pos; std::vector<std::vector<_edge>> g; }; } // namespace atcoder #endif // ATCODER_MINCOSTFLOW_HPP #ifndef ATCODER_SCC_HPP #define ATCODER_SCC_HPP 1 #include <algorithm> #include <cassert> #include <vector> namespace atcoder { struct scc_graph { public: scc_graph() : internal(0) {} scc_graph(int n) : internal(n) {} void add_edge(int from, int to) { int n = internal.num_vertices(); assert(0 <= from && from < n); assert(0 <= to && to < n); internal.add_edge(from, to); } std::vector<std::vector<int>> scc() { return internal.scc(); } private: internal::scc_graph internal; }; } // namespace atcoder #endif // ATCODER_SCC_HPP #ifndef ATCODER_SEGTREE_HPP #define ATCODER_SEGTREE_HPP 1 #include <algorithm> #include <cassert> #include <vector> namespace atcoder { template <class S, S (*op)(S, S), S (*e)()> struct segtree { public: segtree() : segtree(0) {} segtree(int n) : segtree(std::vector<S>(n, e())) {} segtree(const std::vector<S>& v) : _n(int(v.size())) { log = internal::ceil_pow2(_n); size = 1 << log; d = std::vector<S>(2 * size, e()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { assert(0 <= p && p < _n); p += size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) { assert(0 <= p && p < _n); return d[p + size]; } S prod(int l, int r) { assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += size; r += size; while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } template <bool (*f)(S)> int max_right(int l) { return max_right(l, [](S x) { return f(x); }); } template <class F> int max_right(int l, F f) { assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += size; S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*f)(S)> int min_left(int r) { return min_left(r, [](S x) { return f(x); }); } template <class F> int min_left(int r, F f) { assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += size; S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector<S> d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; } // namespace atcoder #endif // ATCODER_SEGTREE_HPP #ifndef ATCODER_STRING_HPP #define ATCODER_STRING_HPP 1 #include <algorithm> #include <cassert> #include <numeric> #include <string> #include <vector> namespace atcoder { namespace internal { std::vector<int> sa_naive(const std::vector<int>& s) { int n = int(s.size()); std::vector<int> sa(n); std::iota(sa.begin(), sa.end(), 0); std::sort(sa.begin(), sa.end(), [&](int l, int r) { if (l == r) return false; while (l < n && r < n) { if (s[l] != s[r]) return s[l] < s[r]; l++; r++; } return l == n; }); return sa; } std::vector<int> sa_doubling(const std::vector<int>& s) { int n = int(s.size()); std::vector<int> sa(n), rnk = s, tmp(n); std::iota(sa.begin(), sa.end(), 0); for (int k = 1; k < n; k *= 2) { auto cmp = [&](int x, int y) { if (rnk[x] != rnk[y]) return rnk[x] < rnk[y]; int rx = x + k < n ? rnk[x + k] : -1; int ry = y + k < n ? rnk[y + k] : -1; return rx < ry; }; std::sort(sa.begin(), sa.end(), cmp); tmp[sa[0]] = 0; for (int i = 1; i < n; i++) { tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0); } std::swap(tmp, rnk); } return sa; } // SA-IS, linear-time suffix array construction // Reference: // G. Nong, S. Zhang, and W. H. Chan, // Two Efficient Algorithms for Linear Time Suffix Array Construction template <int THRESHOLD_NAIVE = 10, int THRESHOLD_DOUBLING = 40> std::vector<int> sa_is(const std::vector<int>& s, int upper) { int n = int(s.size()); if (n == 0) return {}; if (n == 1) return {0}; if (n == 2) { if (s[0] < s[1]) { return {0, 1}; } else { return {1, 0}; } } if (n < THRESHOLD_NAIVE) { return sa_naive(s); } if (n < THRESHOLD_DOUBLING) { return sa_doubling(s); } std::vector<int> sa(n); std::vector<bool> ls(n); for (int i = n - 2; i >= 0; i--) { ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]); } std::vector<int> sum_l(upper + 1), sum_s(upper + 1); for (int i = 0; i < n; i++) { if (!ls[i]) { sum_s[s[i]]++; } else { sum_l[s[i] + 1]++; } } for (int i = 0; i <= upper; i++) { sum_s[i] += sum_l[i]; if (i < upper) sum_l[i + 1] += sum_s[i]; } auto induce = [&](const std::vector<int>& lms) { std::fill(sa.begin(), sa.end(), -1); std::vector<int> buf(upper + 1); std::copy(sum_s.begin(), sum_s.end(), buf.begin()); for (auto d : lms) { if (d == n) continue; sa[buf[s[d]]++] = d; } std::copy(sum_l.begin(), sum_l.end(), buf.begin()); sa[buf[s[n - 1]]++] = n - 1; for (int i = 0; i < n; i++) { int v = sa[i]; if (v >= 1 && !ls[v - 1]) { sa[buf[s[v - 1]]++] = v - 1; } } std::copy(sum_l.begin(), sum_l.end(), buf.begin()); for (int i = n - 1; i >= 0; i--) { int v = sa[i]; if (v >= 1 && ls[v - 1]) { sa[--buf[s[v - 1] + 1]] = v - 1; } } }; std::vector<int> lms_map(n + 1, -1); int m = 0; for (int i = 1; i < n; i++) { if (!ls[i - 1] && ls[i]) { lms_map[i] = m++; } } std::vector<int> lms; lms.reserve(m); for (int i = 1; i < n; i++) { if (!ls[i - 1] && ls[i]) { lms.push_back(i); } } induce(lms); if (m) { std::vector<int> sorted_lms; sorted_lms.reserve(m); for (int v : sa) { if (lms_map[v] != -1) sorted_lms.push_back(v); } std::vector<int> rec_s(m); int rec_upper = 0; rec_s[lms_map[sorted_lms[0]]] = 0; for (int i = 1; i < m; i++) { int l = sorted_lms[i - 1], r = sorted_lms[i]; int end_l = (lms_map[l] + 1 < m) ? lms[lms_map[l] + 1] : n; int end_r = (lms_map[r] + 1 < m) ? lms[lms_map[r] + 1] : n; bool same = true; if (end_l - l != end_r - r) { same = false; } else { while (l < end_l) { if (s[l] != s[r]) { break; } l++; r++; } if (l == n || s[l] != s[r]) same = false; } if (!same) rec_upper++; rec_s[lms_map[sorted_lms[i]]] = rec_upper; } auto rec_sa = sa_is<THRESHOLD_NAIVE, THRESHOLD_DOUBLING>(rec_s, rec_upper); for (int i = 0; i < m; i++) { sorted_lms[i] = lms[rec_sa[i]]; } induce(sorted_lms); } return sa; } } // namespace internal std::vector<int> suffix_array(const std::vector<int>& s, int upper) { assert(0 <= upper); for (int d : s) { assert(0 <= d && d <= upper); } auto sa = internal::sa_is(s, upper); return sa; } template <class T> std::vector<int> suffix_array(const std::vector<T>& s) { int n = int(s.size()); std::vector<int> idx(n); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int l, int r) { return s[l] < s[r]; }); std::vector<int> s2(n); int now = 0; for (int i = 0; i < n; i++) { if (i && s[idx[i - 1]] != s[idx[i]]) now++; s2[idx[i]] = now; } return internal::sa_is(s2, now); } std::vector<int> suffix_array(const std::string& s) { int n = int(s.size()); std::vector<int> s2(n); for (int i = 0; i < n; i++) { s2[i] = s[i]; } return internal::sa_is(s2, 255); } // Reference: // T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park, // Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its // Applications template <class T> std::vector<int> lcp_array(const std::vector<T>& s, const std::vector<int>& sa) { int n = int(s.size()); assert(n >= 1); std::vector<int> rnk(n); for (int i = 0; i < n; i++) { rnk[sa[i]] = i; } std::vector<int> lcp(n - 1); int h = 0; for (int i = 0; i < n; i++) { if (h > 0) h--; if (rnk[i] == 0) continue; int j = sa[rnk[i] - 1]; for (; j + h < n && i + h < n; h++) { if (s[j + h] != s[i + h]) break; } lcp[rnk[i] - 1] = h; } return lcp; } std::vector<int> lcp_array(const std::string& s, const std::vector<int>& sa) { int n = int(s.size()); std::vector<int> s2(n); for (int i = 0; i < n; i++) { s2[i] = s[i]; } return lcp_array(s2, sa); } // Reference: // D. Gusfield, // Algorithms on Strings, Trees, and Sequences: Computer Science and // Computational Biology template <class T> std::vector<int> z_algorithm(const std::vector<T>& s) { int n = int(s.size()); if (n == 0) return {}; std::vector<int> z(n); z[0] = 0; for (int i = 1, j = 0; i < n; i++) { int& k = z[i]; k = (j + z[j] <= i) ? 0 : std::min(j + z[j] - i, z[i - j]); while (i + k < n && s[k] == s[i + k]) k++; if (j + z[j] < i + z[i]) j = i; } z[0] = n; return z; } std::vector<int> z_algorithm(const std::string& s) { int n = int(s.size()); std::vector<int> s2(n); for (int i = 0; i < n; i++) { s2[i] = s[i]; } return z_algorithm(s2); } } // namespace atcoder #endif // ATCODER_STRING_HPP #ifndef ATCODER_TWOSAT_HPP #define ATCODER_TWOSAT_HPP 1 #include <cassert> #include <vector> namespace atcoder { // Reference: // B. Aspvall, M. Plass, and R. Tarjan, // A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean // Formulas struct two_sat { public: two_sat() : _n(0), scc(0) {} two_sat(int n) : _n(n), _answer(n), scc(2 * n) {} void add_clause(int i, bool f, int j, bool g) { assert(0 <= i && i < _n); assert(0 <= j && j < _n); scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0)); scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0)); } bool satisfiable() { auto id = scc.scc_ids().second; for (int i = 0; i < _n; i++) { if (id[2 * i] == id[2 * i + 1]) return false; _answer[i] = id[2 * i] < id[2 * i + 1]; } return true; } std::vector<bool> answer() { return _answer; } private: int _n; std::vector<bool> _answer; internal::scc_graph scc; }; } // namespace atcoder #endif // ATCODER_TWOSAT_HPP #include <bits/stdc++.h> #define int long long #define sint signed #define endl "\n" // fflush(stdout); #define ALL(v) (v).begin(),(v).end() #define Vi vector<int> #define VVi vector<Vi> #define VVVi vector<VVi> #define Vm vector<mint> #define Vs vector<string> #define Vd vector<double> #define Vc vector<char> #define Pii pair<int,int> #define Pdd pair<double,double> #define VPii vector<Pii> #define Tiii tuple<int,int,int> #define VTiii vector<Tiii> #define PQi priority_queue<int> #define PQir priority_queue<int,vector<int>,greater<int>> #define pb push_back #define mp make_pair #define mt make_tuple #define itos to_string #define stoi stoll #define FI first #define SE second #define cYES cout<<"YES"<<endl #define cNO cout<<"NO"<<endl #define cYes cout<<"Yes"<<endl #define cNo cout<<"No"<<endl #define cyes cout<<"yes"<<endl #define cno cout<<"no"<<endl #define sortr(v) sort(v,greater<>()) #define rep(i,a,b) for(int i=a;i<b;i++) #define repeq(i,a,b) for(int i=a;i<=b;i++) #define repreq(i,a,b) for(int i=a;i>=b;i--) #define dem(a,b) ((a+b-1)/(b)) #define INF 3000000000000000000 // 3.0*10^18 #define MAX LLONG_MAX #define PI acos(-1.0L) using namespace std; using namespace atcoder; /* debug */ template <typename T> ostream& operator<<(ostream& os,const vector<T> &V){int N=V.size(); if(N==0){os<<'.';return os;}rep(i,0,N-1){os<<V[i]<<' ';}os<<V[N-1];return os;} template <typename T> ostream& operator<<(ostream& os,const vector<vector<T>> &V){ int N=V.size();rep(i,0,N-1)os<<V[i]<<endl;os<<V[N-1];return os;} template <typename T,typename S> ostream& operator<<(ostream& os, pair<T,S> const&P){os<<P.FI<<' '<<P.SE;return os;} /* useful */ template<typename T>void Vin(vector<T> &v){int n=v.size();rep(i,0,n)cin>>v[i];} int scomb(int n, int r){if(r<0||r>n)return 0;if((n-r)<r)r=n-r; // nCr int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;} Vi vis(Vi &v){Vi S(v.size()+1);rep(i,1,S.size())S[i]+=v[i-1]+S[i-1];return S;} int digit_sum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} int digit(int k,int i){string s = itos(k);return s[s.size()-i]-'0';} // i桁目の数字 template<typename T>void press(T &v){v.erase(unique(ALL(v)),v.end());} // 圧縮 Vi zip(Vi b){int Z=b.size(); // 座標圧縮 Pii p[Z+10];int a=b.size();Vi l(a);for(int i=0;i<a;i++) p[i]=mp(b[i],i);sort(p,p+a);int w=0;for(int i=0;i<a;i++) {if(i&&p[i].first!=p[i-1].first)w++;l[p[i].second]=w;}return l;} int SMALLER(Vi &a,int x){return lower_bound(a.begin(),a.end(),x)-a.begin();} int orSMALLER(Vi &a,int x){return upper_bound(a.begin(),a.end(),x)-a.begin();} int BIGGER(Vi &a,int x){return a.size()-orSMALLER(a,x);} int orBIGGER(Vi &a,int x){return a.size()-SMALLER(a,x);} int COUNT(Vi &a,int x) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} int maxind(Vi &a){return max_element(ALL(a))-a.begin();} int minind(Vi &a){return min_element(ALL(a))-a.begin();} //const int MOD = 998244353; const int MOD = 1000000007; const double EPS = 1e-10; using mint = modint; void init(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); mint::set_mod(MOD); } /************************************ START ************************************/ int f(int n,int k){ int ret = 0; int now = n,ke = k; while(now!=0){ ret += now%ke; now /= ke; } return ret; } signed main() { init(); int n,K;cin >> n >> K; if(K > n) {cout << -1 << endl;return 0;} if(n==K) {out << b+1 << endl;return 0;} //repreq(i,n,2){cerr << i << " : " << f(n,i) << endl;} repeq(i,2,100005){ if(f(n,i)==K) {cout << i << endl;return 0;} } if(n <= 100000){ cout << -1 << endl; return 0; } Vi b; repeq(i,1,n){ b.pb(n/i); if(n/i < 50000) break; } //cout << b << endl; int ans = INF; rep(i,0,b.size()){ int L,R; L = f(n,b[i]); R = L+(b[i]-b[i+1]-1)*(i+1); //cerr << L <<' '<< R << endl; if(K > R || K < L || K%(i+1)!=L%(i+1)) continue; int sa = K-L; sa /= (i+1); ans = min(ans,b[i]-sa); if(b[i] < 90000) break; } if(ans == INF) ans = -1; cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:1964:13: error: 'out' was not declared in this scope 1964 | if(n==K) {out << b+1 << endl;return 0;} | ^~~ a.cc:1964:20: error: 'b' was not declared in this scope 1964 | if(n==K) {out << b+1 << endl;return 0;} | ^
s469467388
p04016
C++
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() typedef long long ll; ll n, s; ll ans = 1e18; const int N = 317000; void check(int b) { ll v = n, sum = 0; while (v) { sum += v % b; v /= b; } if (sum == s) { ans = min(ans, b); } } void relax(ll a) { ll b = s - a; ll B = (n - s) / a + 1; if (a < B && b < B && 0 <= b && 2 <= B && a * B + b == n) { ans = min(ans, B); } } void twoDigits() { if (n - s <= 0) return; ll v = n - s; for (ll mul = 1; mul * mul <= v; mul++) { if (v % mul == 0) { relax(mul); relax(v / mul); } } } void solve() { cin >> n >> s; if (s == 1) { ans = n; } if (n == s) { ans = min(ans, n + 1); } for (int b = 2; b < N; b++) { check(b); } twoDigits(); cout << (ans == 1e18 ? -1 : ans); } // CHECK LIMITS (n <= 10^5) // CHECK CORNER CASES (n == 1) int main() { ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(20); //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl; solve(); }
a.cc: In function 'void check(int)': a.cc:19:14: error: no matching function for call to 'min(ll&, int&)' 19 | ans = min(ans, b); | ~~~^~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:19:14: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 19 | ans = min(ans, b); | ~~~^~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:19:14: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 19 | ans = min(ans, b); | ~~~^~~~~~~~
s625769792
p04016
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxN = 2e5 + 10; const ll oo = 1e18; ll n, m; ll f(ll x, ll d) { if (x > d) return d; return (d % x) + f(x, d / x); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout); cin >> n >> m; ll ans = oo; if (m > n) return cout << -1, 0; if (n == m) ans = min(ans, n + 1); for (ll i = 2; i * i <= n; ++i) { if (f(i, n) == m) ans = min(ans, i); } ll k = n - m; ll block = sqrt(n); for (ll i = 1; i * i <= k; ++i) { if (i > m) break; ll p = i, ans = k / i + 1; ll q = n - (x * y); if (q < y && q < m) ans = min(ans, y); } cout << (ans == oo ? -1 : ans); return 0; }
a.cc: In function 'int main()': a.cc:31:17: error: 'x' was not declared in this scope 31 | ll q = n - (x * y); | ^ a.cc:31:21: error: 'y' was not declared in this scope 31 | ll q = n - (x * y); | ^
s528836463
p04016
C++
#include <iostream> #include <utility> #include <tuple> #include <vector> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <algorithm> #include <functional> #include <climits> #include <numeric> #include <queue> #include <cmath> #include <iomanip> #include <array> #include <string> #include <stack> #include <cassert> #include <memory> long long int f(const long long int b, const long long int n) { return n < b ? n : f(b, n / b) + n % b; } int main() { long long int n, s; std::cin >> n >> s; if (n < s) { std::cout << "-1\n"; return 0; } long long int b = 2LL; for (; b * b <= n; ++b) { if (f(b, n) == s) { std::cout << b << std::endl; return 0; } } const auto p = (n - s) / b + 1; if (p > 1 && f(p, n) == s) { std::cout << p << std::endl; return 0; } } if (n == s) { std::cout << n + 1 << std::endl; return 0; } std::cout << "-1\n"; }
a.cc:45:9: error: expected unqualified-id before 'if' 45 | if (n == s) { | ^~ a.cc:49:14: error: 'cout' in namespace 'std' does not name a type 49 | std::cout << "-1\n"; | ^~~~ In file included from a.cc:1: /usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here 63 | extern ostream cout; ///< Linked to standard output | ^~~~ a.cc:50:1: error: expected declaration before '}' token 50 | } | ^
s494158316
p04016
C++
#include <bits/stdc++.h> using namespace std; long long f(long long n, long long k) { long long rt = 0; while (n > 0) { rt += n % k; n /= k; } return rt; } int main() { long long n, s; cin >> n >> s; long long ans = -1; long long B = 0; for (long long i = 2; i * i <= n; i++) { if (f(n, i) == s) { //ans += i; cout << i << endl; return 0; } B = i; } for (long long i = 1; i * i <= (n - s); i++) { if ((n - s) % i == 0) { long long k = (n - s) / i + 1; if (k <= B|| k == 1) continue; if (f(n, k) == i) { ans = k; } } } if (ans == -1 && n == k) ans = n + 1; cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:36:27: error: 'k' was not declared in this scope 36 | if (ans == -1 && n == k) ans = n + 1; | ^
s409171603
p04016
C++
n=int(input()) s=int(input()) import math #first solve assuming b<=sqrt(n) sq=int(math.sqrt(n)) for b in range(2,sq+2): num=n su=0 while num>=b: su+=num%b num//=b su+=num if su==s: print(b) exit() #answer not found yet so check in the divisors of n-s nn=n-s if nn==0: print(n+1) exit() ans=float('inf') b=2 while b*b<=nn and nn>0: if nn%b==0: num=n su=0 bb=nn//b while num>=bb: su+=num%bb num//=bb su+=num if su==s: ans=min(ans,bb) ''' if b!=nn//b: bb=nn//b num=n su=0 while num>=bb: su+=num%bb num//=b su+=num if su==s: ans=min(ans,bb) ''' b+=1 b=nn num=n su=0 while num>=b and nn>0: su+=num%b num//=b su+=num if su==s: ans=min(ans,b) b=n num=n su=0 while num>=b and b>1: su+=num%b num//=b su+=num if su==s: ans=min(ans,b) if ans!=float('inf'): print(ans) else: print('-1')
a.cc:4:2: error: invalid preprocessing directive #first 4 | #first solve assuming b<=sqrt(n) | ^~~~~ a.cc:16:2: error: invalid preprocessing directive #answer 16 | #answer not found yet so check in the divisors of n-s | ^~~~~~ a.cc:21:11: warning: multi-character character constant [-Wmultichar] 21 | ans=float('inf') | ^~~~~ a.cc:34:9: error: empty character constant 34 | ''' | ^~ a.cc:34:11: warning: missing terminating ' character 34 | ''' | ^ a.cc:34:11: error: missing terminating ' character a.cc:45:9: error: empty character constant 45 | ''' | ^~ a.cc:45:11: warning: missing terminating ' character 45 | ''' | ^ a.cc:45:11: error: missing terminating ' character a.cc:66:15: warning: multi-character character constant [-Wmultichar] 66 | if ans!=float('inf'): | ^~~~~ a.cc:69:11: warning: multi-character character constant [-Wmultichar] 69 | print('-1') | ^~~~ a.cc:1:1: error: 'n' does not name a type 1 | n=int(input()) | ^
s804106523
p04016
C++
cout << -1 << endl;
a.cc:1:2: error: 'cout' does not name a type 1 | cout << -1 << endl; | ^~~~
s048115677
p04016
C++
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VRSORT(v) sort(v.begin(), v.end(),greater<int>()); #define INF 999999999 #define MOD 1000000007 #define M_PI 3.14159265358979323846 #define ALL(X) (X).begin(),(X).end() #ifdef __LOCAL #define DBG(X) cout << #X << " = " << (X) << endl; #define SAY(X) cout << (X) << endl; #else #define DBG(X) #define SAY(X) #endif #ifdef __LOCAL #include <filesystem> namespace fs = std::filesystem; #endif using namespace std; using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; int dx[]={1, 0, -1, 0, 0}; int dy[]={0, 1, 0, -1, 0}; const int INT_INF = (int)(2e9); const ll LL_INF = (ll)(2e18); const int NIL = -1; static mt19937 _g(time(nullptr)); std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;} inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); } inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }; template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); } template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; } template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline T fetch() { T ret; cin >> ret; return ret; } template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; } ll N,S; void input(){ #ifdef __LOCAL fs::path p = __FILE__; fs::path input,output; input = output = p.parent_path(); input += string("/input/") + string(p.stem()) + string(".txt"); output += string("/output/") + string(p.stem()) + string(".txt"); freopen(input.c_str(), "r", stdin); freopen(output.c_str(), "w", stdout); #endif cin >> N >> S; } ll func(ll b, ll n){ if(n<b) return n; else return func(b,n/b)+n%b; } int solve(){ if(S>(N+1)/2) {cout << -1 << endl; return 0;} for (ll i = 2; i*i <= N; i++) { if(func(i,N)==S) {cout << i << endl; return 0;} } for (ll q = 1; q*q <= N; q++) { ll b = 1+(N-s)/q; if(func(b,N)==S) cout << b << endl; return 0;} } if(func(N+1,N)==S) {cout << N+1 << endl; return 0;} cout << -1 << endl; return 0; } int test(int n){ vector<int> cnt(n,0); for (int i = 2; i <= n; i++) { ll f=func(i,n); cnt[f]++; cout << f << "," << endl; } cout << cnt << endl; return 0; } int main() { input(); // test(101); solve(); return 0; }
a.cc: In function 'int solve()': a.cc:79:17: error: 's' was not declared in this scope 79 | ll b = 1+(N-s)/q; | ^ a.cc: At global scope: a.cc:82:3: error: expected unqualified-id before 'if' 82 | if(func(N+1,N)==S) {cout << N+1 << endl; return 0;} | ^~ a.cc:83:3: error: 'cout' does not name a type 83 | cout << -1 << endl; | ^~~~ a.cc:84:3: error: expected unqualified-id before 'return' 84 | return 0; | ^~~~~~ a.cc:85:1: error: expected declaration before '}' token 85 | } | ^ a.cc: In function 'int solve()': a.cc:81:3: warning: control reaches end of non-void function [-Wreturn-type] 81 | } | ^
s444704596
p04016
C++
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <iomanip> using namespace std; typedef long long ll; ll f(ll b, ll n) { ll ans=0; while (n) { ans += (n % b); n /= b; } return ans; } int main() { ll n, s; scanf_s("%lld%lld", &n, &s); if (s == n) { printf("%lld\n", n + 1); return 0; } ll t = (ll)sqrt(n)+1; for(ll i=2;i<=t;i++) if (f(i, n) == s) { printf("%d\n", i); return 0; } n -= s; ll r = (ll)1e11 + 10; for (ll p = 1; p * p <= n; p++) { if (n % p == 0) { ll b = n / p + 1; ll a0 = s - p; ll a1 = p; if (b >= 2 && a0 >= 0 && a0 < b && a1 >= 0 && a1 < b) { r = min(r, b); } } } if (r != (ll)1e11 + 10) { printf("%lld\n",r); return 0; } printf("-1\n"); return 0; }
a.cc: In function 'int main()': a.cc:25:9: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'? 25 | scanf_s("%lld%lld", &n, &s); | ^~~~~~~ | scanf
s697716496
p04016
C++
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <iomanip> using namespace std; typedef long long ll; ll f(ll b, ll n) { ll ans=0; while (n) { ans += (n % b); n /= b; } return ans; } int main() { ll n, s; scanf_s("%lld%lld", &n, &s); if (s == n) { printf("%lld\n", n + 1); return 0; } else { for(ll i=2;i<=n;i++) if (f(i, n) == s) { printf("%lld\n", i); return 0; } } printf("-1\n"); return 0; }
a.cc: In function 'int main()': a.cc:25:9: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'? 25 | scanf_s("%lld%lld", &n, &s); | ^~~~~~~ | scanf
s829910510
p04016
C++
#include <bits/stdc++.h> using namespace std; int main() { long long n, s; scanf("%lld%lld", &n, &s); if(n == s) { printf("%lld\n", n + 1); return 0; } if(s == 1) { else printf("%lld\n", n); return 0; } int m = sqrt(n); m++; long long res = -1; for(int i = 2; i <= m; i++) { long long tmp = n, sum = 0; while(tmp) { sum += tmp % i; tmp /= i; } if(sum == s) { res = i; break; } } if(res < 0) { long long tmp = n - s; if(tmp > 0) { for(int i = 2; i * i <= tmp; i++) { if(tmp % i == 0) { long long x = tmp / i + 1, a = i; long long b = s - a; if(x > a && x > b && a * x + b == tmp) { if(res < 0 || res > x) res; } } } } } printf("%lld\n", res); return 0; }
a.cc: In function 'int main()': a.cc:12:17: error: expected '}' before 'else' 12 | else printf("%lld\n", n); | ^~~~ a.cc:11:20: note: to match this '{' 11 | if(s == 1) { | ^ a.cc: At global scope: a.cc:15:22: error: 'n' was not declared in this scope; did you mean 'yn'? 15 | int m = sqrt(n); m++; | ^ | yn a.cc:15:26: error: 'm' does not name a type; did you mean 'tm'? 15 | int m = sqrt(n); m++; | ^ | tm a.cc:17:9: error: expected unqualified-id before 'for' 17 | for(int i = 2; i <= m; i++) { | ^~~ a.cc:17:24: error: 'i' does not name a type 17 | for(int i = 2; i <= m; i++) { | ^ a.cc:17:32: error: 'i' does not name a type 17 | for(int i = 2; i <= m; i++) { | ^ a.cc:28:9: error: expected unqualified-id before 'if' 28 | if(res < 0) { | ^~ a.cc:42:15: error: expected constructor, destructor, or type conversion before '(' token 42 | printf("%lld\n", res); | ^ a.cc:43:9: error: expected unqualified-id before 'return' 43 | return 0; | ^~~~~~ a.cc:44:1: error: expected declaration before '}' token 44 | } | ^
s411579939
p04016
C++
//#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0 #define all(a) a.begin(),a.end() #define len(a) (int)(a.size()) #define elif else if #define mp make_pair #define pb push_back #define fir first #define sec second using namespace std; #define int long long typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef long double ld; typedef long long ll; const int arr=2e5+10; const int ar=2e3+10; const ld pi=acos(-1); const ld eps=1e-10; const ll md=1e9+7; const ll inf=1e18+10; ///---program start---/// const int M=1e6; int sum(int n,int b) { int res=0; while (n){ res+=n%b; n/=b; } return res; } int get_big(int n,int s) { int res=inf; for (int val=1;val<=min({n,s,M});val++){ int rest=s-val; if ((n-rest)%val==0){ int b=(n-rest)/val; if (n/b==val){ if (b>=2){ res=min(res,b); } } } } /// if val==0 if (n==s){ if (n==1){ res=min(res,2); } else{ res=min(res,n); } } return (res==inf?-1:res); } main() { #ifdef Barik files("barik"); freopen("debug.txt","w",stderr); #endif int n,s; cin>>n>>s; for (int b=2;b<M;b++){ if (sum(n,b)==s){ cout<<b<<"\n"; return 0; } } cout<<get_big(n,s)<<"\n"; }
a.cc: In function 'long long int get_big(long long int, long long int)': a.cc:63:20: error: no matching function for call to 'min(long long int&, int)' 63 | res=min(res,2); | ~~~^~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:4: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:63:20: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 63 | res=min(res,2); | ~~~^~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:63:20: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 63 | res=min(res,2); | ~~~^~~~~~~ a.cc: At global scope: a.cc:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 72 | main() | ^~~~
s602955166
p04016
C++
#include <iostream> #include <climits> using namespace std; long long digitsum(long long b, long long n) { long long result = 0; while (n > 0) { result += n % b; n /= b; } return result; } int main() { long long n, s, result = LLONG_MAX; cin >> n >> s; if (n == s) { result = n + 1; } else { for (long long b = 2; b * b <= n; b++) { if (digitsum(b, n) == s) { result = b; break; } } for (long long b = 2; b * b <= n - s; b++) { if ((n - s) % b == 0) { if (digitsum((n - s) / b, n) == s) { result = min(result, (n - s) / b); } if (digitsum(b, n) == s) { result = min(result, b); } } } if (n - s > 1 && digitsum(n - s, n) == s) { result = min(n - s, b); } if (s == 1) { result = min(result, n); } } if (result == LLONG_MAX) { result = -1; } cout << result; return 0; }
a.cc: In function 'int main()': a.cc:37:33: error: 'b' was not declared in this scope 37 | result = min(n - s, b); | ^
s698552893
p04016
C++
#include <iostream> #include <algorithm> using namespace std; long long digitsum(long long b, long long n) { long long result = 0; while (n > 0) { result += n % b; n /= b; } return result; } int main() { long long n, s; unsigned long long result = -1; cin >> n >> s; for (long long b = 2; b * b <= n; b++) { if (digitsum(b, n) == s) { result = b; break; } } for (long long b = 2; b * b <= n - s; b++) { if ((n - s) % b == 0) { if (digitsum((n - s) / b, n) == s) { result = min(result, (n - s) / b); } if (digitsum(b, n) == s) { result = min(result, b); } } } if (digitsum(n - s, n) == s) { result = min(result, n - s); } if (s == 1) { result = min(result, n); } cout << result; return 0; }
a.cc: In function 'int main()': a.cc:27:29: error: no matching function for call to 'min(long long unsigned int&, long long int)' 27 | result = min(result, (n - s) / b); | ~~~^~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:27:29: note: deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int') 27 | result = min(result, (n - s) / b); | ~~~^~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61, from a.cc:2: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:27:29: note: mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int' 27 | result = min(result, (n - s) / b); | ~~~^~~~~~~~~~~~~~~~~~~~~ a.cc:30:29: error: no matching function for call to 'min(long long unsigned int&, long long int&)' 30 | result = min(result, b); | ~~~^~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:30:29: note: deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int') 30 | result = min(result, b); | ~~~^~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:30:29: note: mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int' 30 | result = min(result, b); | ~~~^~~~~~~~~~~ a.cc:35:21: error: no matching function for call to 'min(long long unsigned int&, long long int)' 35 | result = min(result, n - s); | ~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:35:21: note: deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int') 35 | result = min(result, n - s); | ~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:35:21: note: mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int' 35 | result = min(result, n - s); | ~~~^~~~~~~~~~~~~~~ a.cc:38:21: error: no matching function for call to 'min(long long unsigned int&, long long int&)' 38 | result = min(result, n); | ~~~^~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:38:21: note: deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int') 38 | result = min(result, n); | ~~~^~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:38:21: note: mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int' 38 | result = min(result, n); | ~~~^~~~~~~~~~~
s753189788
p04016
C++
#include<bits/stdc++.h> #define LL long long #define MAXN 50005 #define INF (1<<25) #define P int(998244353) using namespace std; LL n,s; bool chk(LL b){ LL res = 0; LL x = n; while(x){ res += x%b; x /= b; } return (s==res); } int main(){ cin>>n>>s; if(s==1){ cout<<max(2,n)<<endl; return 0; } if(n==s){ cout<<n+1<<endl; return 0; } LL ans = 1e18; for(LL b=2;b*b<=n;b++){ if(chk(b)){ ans = b; break; } } /* bx + y = n x + y = s (b-1)*x = n-s */ if(ans==1e18 && n-s<=0){ cout<<"-1"<<endl; return 0; } LL b,y; for(LL x=1;x*x<=n-s;x++){ if((n-s)%x==0){ b = (n-s)/x + 1; y = s - x; if(x>=0 && y>=0 && n<b*b && y<b && x<b){ ans = min(ans, b); } // b = x + 1; y = s - (n-s)/(b-1); if(x>=0 && y>=0 && n<b*b && y<b && x<b){ ans = min(ans, b); } } } if(ans==1e18) ans = -1; cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:25:26: error: no matching function for call to 'max(int, long long int&)' 25 | cout<<max(2,n)<<endl; | ~~~^~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:25:26: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 25 | cout<<max(2,n)<<endl; | ~~~^~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:25:26: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 25 | cout<<max(2,n)<<endl; | ~~~^~~~~
s293482841
p04016
C++
#include <bits/stdc++.h> using namespace std; long long f(long long b, long long n){ if (n < b) return n; return f(b, n / b) + n % b; } int main(){ long long n, s; scanf("%lld %lld", &n, &s); if (n == s){ printf("%lld\n", n + 1); return 0; for (long long i = 2; i * i <= n; i++){ } if (f(i, n) == s){ printf("%lld\n", i); return 0; } } long long ans = -1; for (long long i = sqrt(n * 1.0); i >= 1; i--){ long long b = (n - s) / i + 1; if (b >= 2 && f(b, n) == s){ printf("%lld\n", b); return 0; } } printf("%lld\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:19:15: error: 'i' was not declared in this scope 19 | if (f(i, n) == s){ | ^
s490813967
p04016
C++
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define fi first #define se second #define mp make_pair #define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++) template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >; typedef long long llong; char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; char moji3[10]={'0','1','2','3','4','5','6','7','8','9'}; #define Sort(a) sort(a.begin(),a.end()); #define Reverse(a) reverse(a.begin(),a.end()); #define print(a) cout << a << endl; #define MOD llong(1e9+7) #define MAX int(2 * 1e5 +5) #define debug(x) cout << #x << " = " << (x) << endl; #define pi acos(-1.0) #define int llong #define INF llong(1e17) template<class T> bool chmax(T &a, T b) {if(a<b){a=b; return 1;} return 0;} template<class T> bool chmin(T &a, T b) {if(a>b){a=b; return 1;} return 0;} bool Add(int &a,int b){a = (a + b) % MOD;} void myprint(int* A,int A_num){ REP(i,A_num) cout << A[i] << " "; cout << endl; } int solve(int b , int n){ int res = 0; while(n > 0){ res += n % b; n /= b; } return res; } signed main(){ int n,s; cin >> n >> s; int b = 2; int ans = INF; if(n < 100){ while(1){ if(solve(b,n) == s){ cout << b << endl; return 0; } } b ++; if(b > n + 1){ cout << - 1 << endl; return 0; } } while(1){ if( (b -1 ) * (b - 1) > n ) break; if(solve(b,n) == s){ cout << b << endl; return 0; } b ++; } int ans = INF; int shou = 1; while( (shou + 1) * (shou + 1) < n) shou++; while(shou > 0){ int amari = s - shou; if( amari >= 0 and (n - amari) % shou == 0){ b = (n - amari) / shou; if(amari < b and shou < b){ chmin(ans,b); } } shou --; } if(ans == INF) cout << - 1 << endl; else cout << ans << endl; }
a.cc: In function 'bool Add(llong&, llong)': a.cc:26:42: warning: no return statement in function returning non-void [-Wreturn-type] 26 | bool Add(int &a,int b){a = (a + b) % MOD;} | ^ a.cc: In function 'int main()': a.cc:71:9: error: redeclaration of 'llong ans' 71 | int ans = INF; | ^~~ a.cc:47:9: note: 'llong ans' previously declared here 47 | int ans = INF; | ^~~
s841612682
p04016
C++
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define fi first #define se second #define mp make_pair #define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++) template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >; typedef long long llong; char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; char moji3[10]={'0','1','2','3','4','5','6','7','8','9'}; #define Sort(a) sort(a.begin(),a.end()); #define Reverse(a) reverse(a.begin(),a.end()); #define print(a) cout << a << endl; #define MOD llong(1e9+7) #define MAX int(2 * 1e5 +5) #define debug(x) cout << #x << " = " << (x) << endl; #define pi acos(-1.0) #define int llong #define INF llong(1e17) template<class T> bool chmax(T &a, T b) {if(a<b){a=b; return 1;} return 0;} template<class T> bool chmin(T &a, T b) {if(a>b){a=b; return 1;} return 0;} bool Add(int &a,int b){a = (a + b) % MOD;} void myprint(int* A,int A_num){ REP(i,A_num) cout << A[i] << " "; cout << endl; } int solve(int b , int n){ int res = 0; while(n > 0){ res += n % b; n /= b; } return res; } signed main(){ int n,s; cin >> n >> s; int b = 2; int ans = INF; if(n < 100000){ while(1){ if(solve(b,n)) == s){ cout << b << endl; return 0; } } b ++; if(b > n + 1) cout << - 1 << endl; } while(1){ if( (b -1 ) * (b - 1) > n ) break; if(solve(b,n) == s){ chmin(ans,b); } b ++; } int shou = 2; while( shou * shou <= n) shou++; while(shou > 0){ int amari = s - shou; if( amari >= 0 and (n - amari) % shou == 0){ b = (n - amari) / shou; if(amari < b and shou < b){ chmin(ans,b); } } shou --; } if(ans == INF) cout << - 1 << endl; else cout << ans << endl; }
a.cc: In function 'bool Add(llong&, llong)': a.cc:26:42: warning: no return statement in function returning non-void [-Wreturn-type] 26 | bool Add(int &a,int b){a = (a + b) % MOD;} | ^ a.cc: In function 'int main()': a.cc:50:28: error: expected primary-expression before '==' token 50 | if(solve(b,n)) == s){ | ^~
s819106178
p04016
C++
#include <bits/stdc++.h> #define pb push_back #define ll long long #define mp make_pair #define inf 1000000007 #define int long long using namespace std; signed main(){ ll n,s; cin>>n>>s; if(n<s){ cout<<-1<<endl; return 0; } if(n==s){ cout<<n+1<<endl; return 0; } for(int i=2;i*i<=n;i++){ ll sum = 0; ll cur = n; while(cur>0){ sum += cur%i; cur /= i; } if(sum == s){ cout<<i<<endl; return 0; } } vector<ll> ldiv; for(int i=1;i*i<=n;i++){ if( (n-s)%i == 0){ ldiv.pb((n-s)/i + 1); //cout<<ldiv[ldiv.size()-1]<<endl; } } sort(ldiv.begin(),ldiv.end()); for(int i=0;i<ldiv.size();i++){ ll ct = ldiv[i]; double sq = sqrt(1.0*n) if(1.0*ct>sq && n/ct+n%ct==s){ cout<<ct<<endl; return 0; } } cout<<-1<<endl; return 0; }
a.cc: In function 'int main()': a.cc:42:17: error: expected ',' or ';' before 'if' 42 | if(1.0*ct>sq && n/ct+n%ct==s){ | ^~
s669660960
p04016
C++
#include <iostream> #include <cmath> using namespace std; long long digitsum(long long a,long long p){ long long t = 0; while(a>0){ t+=(a%p); a/=p; } return t; } int main(){ long long n,s; cin >> n >> s; //sqrt(n)までは全探索 long long n1 = long(sqrt(n))+1; for(int i = 2;i<=n1;i++){ if(digitsum(n,i)==s){ cout << i << endl; return 0; } } long long n2 = (n/n1)+1; for(int i = n2;i>=1;i--){ long long amari = s-i; if(amari>=0 && (n-amari)%i==0 && amari<(n-amari)/i && (n-amari)/i>=2}){ cout << (n-amari)/i << endl; return 0; } } cout << -1 << endl; }
a.cc: In function 'int main()': a.cc:26:77: error: expected ')' before '}' token 26 | if(amari>=0 && (n-amari)%i==0 && amari<(n-amari)/i && (n-amari)/i>=2}){ | ~ ^ | ) a.cc:26:77: error: expected primary-expression before '}' token a.cc:26:78: error: expected primary-expression before ')' token 26 | if(amari>=0 && (n-amari)%i==0 && amari<(n-amari)/i && (n-amari)/i>=2}){ | ^ a.cc: At global scope: a.cc:31:5: error: 'cout' does not name a type 31 | cout << -1 << endl; | ^~~~ a.cc:32:1: error: expected declaration before '}' token 32 | } | ^
s614777291
p04016
C++
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long ll; vector<ll> yakusu; void calc_yakusu(ll A) { if (A == 1) { yakusu.push_back(1); return; } ll waru = 1; while (waru * waru <= A) { if (A % waru == 0) { yakusu.push_back(waru); if(waru * waru != A) yakusu.push_back(A / waru); } waru++; } } int main() { ll n, s; cin >> n >> s; if (s == 1) { cout << n << endl; return 0; } if (s > n) { cout << -1 << endl; return 0; } for (int shinsu = 2; shinsu * shinsu <= n; shinsu++) { ll cpyn = n; ll tmp = 0; while (cpyn > 0)tmp += (cpyn % shinsu), cpyn /= shinsu; if (tmp == s) { cout << shinsu << endl; return 0; } } //n == p * shinsu + q, p + q == s //->q == s - p //n == p * shinsu + s - p //n - s == p * (shinsu - 1) (p > sqrt(n), p < shinsu) calc_yakusu(n - s); sort(yakusu.begin(), yakusu.end()); for (int i = 0; i < yakusu.size(); i++) { ll cur = yakusu[i]; ll counter = (n - s) / yakusu[i]; if (cur > 1 && counter > (ll)sqrt(n) && cur + 1 > counter && cur + 1 > s - counter) { cout << cur + 1 << endl; return 0; } } cout << -1 << endl; return 0; }
a.cc: In function 'int main()': a.cc:61:46: error: 'sqrt' was not declared in this scope 61 | if (cur > 1 && counter > (ll)sqrt(n) && cur + 1 > counter && cur + 1 > s - counter) { | ^~~~
s975007175
p04016
C++
#include<bits/stdc++.h> using namespace std; // Shortcut //#pragma optimize ("O3") #define int long long #define endl '\n' #define eb emplace_back #define pb push_back #define pob pop_back #define mp make_pair #define upb upper_bound #define lwb lower_bound #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define Ford(i, r, l) for (int i = r; i > l; i--) #define FordE(i, r, l) for (int i = r; i >= l; i--) #define Fora(i, a) for (auto i : a) // I/O & Debug #define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' '; #define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl; #define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' '; #define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl; #define Ptest(x) return cout << x, 0; #define gl(s) getline(cin, s); #define setpre(x) fixed << setprecision(x) /* #define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); } void DEB(istream_iterator<string> it) {} template<typename T, typename... Args> void DEB(istream_iterator<string> it, T a, Args... args){ cout << *it << " = " << a << endl; DEB(++it, args...); } */ // Functions //#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') #define bend(a) a.begin(), a.end() #define rbend(a) a.rbegin(), a.rend() #define mset(a) memset(a, 0, sizeof(a)); #define mmset(a) memset(a, 0x3f, sizeof(a)); //mt19937 rando(chrono::steady_clock::now().time_since_epoch().count()); // Data Structure #define pque priority_queue #define mts multiset typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <ld> vld; typedef vector <string> vs; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef vector <vi > vvi; typedef vector <vll > vvll; typedef vector <pii > vpii; typedef vector <pll > vpll; const int N = 2e3 + 5, mod = 1e9 + 7, inf = 1e18 + 7; int n, s; int cal(int x, int y){ int ans = 0; while (y){ ans += y % x; y /= x; } return ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 2; i 8 i <= n; i++){ if (cal(i, n) == s) Ptest(i); } FordE(i, sqrt(n) - 1, 1){ if (s < i) continue; int tmp = n - s + i; if ((tmp % i) != 0) continue; if ((tmp / i) <= (s - i)) continue; if ((tmp / i) == 1) continue; cout << tmp / i; return 0; } if (s == 1 && n == 1){ cout << 2; return 0; } if (s == 1){ cout << n; return 0; } if (s == n){ cout << n + 1; return 0; } cout << -1; } /* ==================================+ INPUT: | ------------------------------ | ------------------------------ | ==================================+ OUTPUT: | ------------------------------ | ------------------------------ | ==================================+ */
a.cc: In function 'int main()': a.cc:84:22: error: expected ';' before numeric constant 84 | for (int i = 2; i 8 i <= n; i++){ | ^~ | ; a.cc:84:24: error: expected ')' before 'i' 84 | for (int i = 2; i 8 i <= n; i++){ | ~ ^~ | ) a.cc:84:33: error: 'i' was not declared in this scope; did you mean 'vi'? 84 | for (int i = 2; i 8 i <= n; i++){ | ^ | vi
s330645026
p04016
C++
#include<bits/stdc++.h> using namespace std; map<long long,map<long long, long long> > f; long long count(long long b,long long n){ if(f[b][n]!=0){ return f[b][n]; } if(n<b){ //cout << b << " " << n<<endl; return n; } else{ f[b][n] = count(b,n/b) + n%b; return f[b][n]; } } signed main(){ long long n,s; cin >> n >> s; long long l=1; long long r=1e11; for(int i=1;i<=10000){ if(count(1,n)==s||count(n-i,n)){ cout << i; return 0; } } cout << "-1"; }
a.cc: In function 'int main()': a.cc:22:29: error: expected ';' before ')' token 22 | for(int i=1;i<=10000){ | ^ | ;
s993957429
p04016
C++
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<set> #include<queue> using namespace std; #define vel vector<long long> #define vvel vector<vel> #define int long long #define rep(i,n) for(long long i=0;i<n;i++) #define sor(v) sort(v.begin(),v.end()) #define mmax(a,b) a=max(a,b) #define mmin(a,b) a=min(a,b) #define mkp make_pair #define pin pair<int,int> #define V vector long long p = 998244353; vel kai(4001, 1); vel ink(4001, 1); vel uni(vel &list) { if (list.size() == 0) { return list; } sort(list.begin(), list.end()); vel ql(1, list[0]); rep(i, list.size() - 1) { if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); } } return ql; } int ru(int a, int r) { if (r == 0) { return 1; } int ans = ru(a, r / 2); ans *= ans; ans %= p; if (r % 2 == 1) { ans *= a; } return ans % p; } int inv(int a) { return ru(a, p - 2); } void make_kai() { rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; } rep(i, 4001) { ink[i] = inv(kai[i]); } } int com(int n, int r) { int ans = kai[n] * ink[r]; ans %= p; ans *= ink[n - r]; ans %= p; return ans; } int dig(int b,int n){ int ans=0; while(n>0){ ans+=n%b;n=n/b; } return ans; } signed main() { int n,s;cin>>n>>s; int dif=n-s; if(dif==0){ cout << n+1<<endl;return 0; } else if(dif<0){cout << -1<<endl;return 0;} else{ vel ans(0); for(int i=1;i*i<=diff;i++){ if(dif%i==0){ int mi=i; if(dig(n,mi+1)==s){ans.push_back(mi+1);} mi=diff/mi; if(dig(n,mi+1)==s){ans.push_back(mi+1);} } } sor(ans); if(ans.size()>0){cout << ans[0]<<endl;} else{cout << -1<<endl;} } return 0; }
a.cc: In function 'int main()': a.cc:65:26: error: 'diff' was not declared in this scope; did you mean 'dif'? 65 | for(int i=1;i*i<=diff;i++){ | ^~~~ | dif
s701273239
p04016
C++
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second void Yes(){ cout<<"Yes"<<endl; exit(0); } void No(){ cout<<"No"<<endl; exit(0); } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, s; cin >> n >> s; if(n == s) { cout << n + 1 << endl; return 0; } if(s > n) { cout << -1 << endl; return 0; } ll b = 2; for(; b * b <= n; b++) { ll N = n; ll f = 0; while(N != 0) { f += N % b; N /= b; } if(f == s) { cout << b << "\n"; return 0; } } b ++; ll N = n - s; for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { if(i >= b - 1 && s >= i + 1 && s <= 2 * i + 1) { cout << i + 1 << endl; return 0; } } } for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { j = n / i; if(j >= b - 1 && s >= j + 1 && s <= 2 * j + 1) { cout << j + 1 << endl; return 0; } } } cout << -1 << endl; return 0; }
a.cc: In function 'int main()': a.cc:86:7: error: 'j' was not declared in this scope 86 | j = n / i; | ^
s353506133
p04016
C++
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second void Yes(){ cout<<"Yes"<<endl; exit(0); } void No(){ cout<<"No"<<endl; exit(0); } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, s; cin >> n >> s; if(n == s) { cout << n + 1 << endl; return 0; } if(s > n) { cout << -1 << endl; return 0; } for(ll b = 2; b * b <= n; b++) { ll N = n; ll f = 0; while(N == 0) { f += N % b; N /= b; } if(f == s) { cout << b << "\n"; return 0; } } b ++; ll N = n - s; vector<ll> divisor; for(ll i = 1; i * i <= n; i++) { if(n % i == 0) { divisor.push_back(i); if(i * i != n) divisor.push_back(n / i); } } sort(divisor.begin(), divisor.end()); for(int i = 0; i < divisor.size(); i++) { if(divisor[i] >= b - 1) { cout << divisor[i] << endl; return 0; } } return 0; }
a.cc: In function 'int main()': a.cc:74:3: error: 'b' was not declared in this scope 74 | b ++; | ^
s301254974
p04016
C++
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 50+5; const int dx[] = {0,0,-1,1,-1,-1,1,1}; const int dy[] = {-1,1,0,0,-1,1,-1,1}; using namespace std; int main() { LL n,s; scanf("%lld%lld",&n,&s); if(n==s) printf("%lld\n",s+1); else if(n<s) printf("-1\n"); else { LL mid=sqrt(n)+1; bool flag=false; //b>sqrt(n) LL res; for(LL i=2; i<=mid; i++) { //枚举b res=0; LL temp=n; while(temp) { res+=temp%i; temp/=i; } if(res==s) { printf("%lld\n",i); flag=true; break; } } //b<=sqrt(n) if(!flag) { LL factor=n-s; LL res; for(LL i=sqrt(n-s)+1;; i>=1; i--) {//枚举x1 if(factor%i==0) { res=factor/i+1; LL j=s-i;//x2 if(i<res&&res>=2&&j<res&&i>=0) { //判断b的合法性 printf("%lld\n",res); flag=true; break; } } } } //其他情况 if(!flag) printf("-1\n"); } return 0; }
a.cc: In function 'int main()': a.cc:56:40: error: expected ')' before ';' token 56 | for(LL i=sqrt(n-s)+1;; i>=1; i--) {//枚举x1 | ~ ^ | ) a.cc:56:42: error: 'i' was not declared in this scope 56 | for(LL i=sqrt(n-s)+1;; i>=1; i--) {//枚举x1 | ^
s626269637
p04016
C++
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 50+5; const int dx[] = {0,0,-1,1,-1,-1,1,1}; const int dy[] = {-1,1,0,0,-1,1,-1,1}; using namespace std; int main() { LL n,s; scanf("%lld%lld",&n,&s); if(n==s) prLLf("%lld\n",s+1); else if(n<s) prLLf("-1\n"); else { LL mid=sqrt(n); bool flag=false; //b>sqrt(n) LL res; for(LL i=2; i<=mid; i++) { //枚举b res=0; LL temp=n; while(temp) { res+=temp%i; temp/=i; } if(res==s) { prLLf("%lld\n",i); flag=true; break; } } //b<=sqrt(n) if(!flag) { LL factor=n-s; LL res; for(LL i=mid; i>=1; i--) {//枚举x1 if(factor%i==0) { res=factor/i+1; LL j=s-i;//x2 if(i<res&&res>=2&&j<res&&i>=0) { //判断b的合法性 prLLf("%lld\n",res); flag=true; break; } } } } //其他情况 if(!flag) prLLf("-1\n"); } return 0; }
a.cc: In function 'int main()': a.cc:29:9: error: 'prLLf' was not declared in this scope 29 | prLLf("%lld\n",s+1); | ^~~~~ a.cc:31:9: error: 'prLLf' was not declared in this scope 31 | prLLf("-1\n"); | ^~~~~ a.cc:46:17: error: 'prLLf' was not declared in this scope 46 | prLLf("%lld\n",i); | ^~~~~ a.cc:61:25: error: 'prLLf' was not declared in this scope 61 | prLLf("%lld\n",res); | ^~~~~ a.cc:71:13: error: 'prLLf' was not declared in this scope 71 | prLLf("-1\n"); | ^~~~~
s200628927
p04016
C++
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long const int MOD = 1E9+7; const int N = 50+5; const int dx[] = {0,0,-1,1,-1,-1,1,1}; const int dy[] = {-1,1,0,0,-1,1,-1,1}; using namespace std; int main() { LL n,s; scanf("%lld%lld",&n,&s); if(n==s) prLLf("%lld\n",s+1); else if(n<s) prLLf("-1\n"); else { LL mid=sqrt(n); bool flag=false; //b>sqrt(n) LL res; for(LL i=2; i<=mid; i++) { //枚举b res=0; LL temp=n; while(temp) { res+=temp%i; temp/=i; } if(res==s) { prLLf("%lld\n",i); flag=true; break; } } //b<=sqrt(n) if(!flag) { LL factor=n-s; LL res; for(LL i=mid; i>=1; i--) {//枚举x1 if(factor%i==0) { res=factor/i+1; LL j=s-i;//x2 if(i<res&&res>=2&&j<res&&i>=0) { //判断b的合法性 prLLf("%lld\n",res); flag=true; break; } } } } //其他情况 if(!flag) prLLf("-1\n"); } return 0; }
a.cc: In function 'int main()': a.cc:29:9: error: 'prLLf' was not declared in this scope 29 | prLLf("%lld\n",s+1); | ^~~~~ a.cc:31:9: error: 'prLLf' was not declared in this scope 31 | prLLf("-1\n"); | ^~~~~ a.cc:46:17: error: 'prLLf' was not declared in this scope 46 | prLLf("%lld\n",i); | ^~~~~ a.cc:61:25: error: 'prLLf' was not declared in this scope 61 | prLLf("%lld\n",res); | ^~~~~ a.cc:71:13: error: 'prLLf' was not declared in this scope 71 | prLLf("-1\n"); | ^~~~~
s438542639
p04016
C++
#include<bits/stdc++.h> using namespace std; #define ll long long ll n,s; bool check(ll base) { ll tmp=n; ll ans=0; while(tmp) { ans+=tmp%base; tmp/=base; } return ans==s; } bool check(ll i,ll sum) { ll a1=s-i;//x0 ll a2=sum/i+1;//b if(a1>=0&&a1<b&&i<a2)return 1; return 0; } int main() { scanf("%lld%lld",&n,&s); /*第一种情况 x0+x1*b^1+x2*b^2+...=n x0+x1+x2+...=s 这个时候b^2<=n 所以b<=根号n 这个时候暴力枚举即可 */ ll Sn=(ll)(sqrt(n))+1; ll base; for(base=2;base<=Sn;base++) { if(check(base)) { printf("%lld\n",base); return 0; } } /* 第二种情况 */ if(n<=s) { if(n==s) { printf("%lld\n",n+1); }else { printf("-1\n"); } } /* 第三种情况暴力枚举 x0+x1*b^1=n; x0+x1=s; 这个时候联立二式子 得到x1*(b-1)=n-s 我们枚举x1,然后判断是否成立,包括题目条件以及进制常识 */ ll sum=n-s; ll up=sum/Sn+1; for(ll i=up;i>=1;i--) { if(!(sum%i)&&(check(i,sum))) { printf("%lld\n",sum/i+1); return 0; } } }
a.cc: In function 'bool check(long long int, long long int)': a.cc:20:18: error: 'b' was not declared in this scope 20 | if(a1>=0&&a1<b&&i<a2)return 1; | ^
s796783279
p04016
C++
#include <bits/stdc++.h> using namespace std; int main(){ long int n, s; cin >> n; cin >> s; bool judge = true; long int i = 2; long int f = 0; long int x; if(n<=s){ cout << -1 << end; } else{ while(judge){ x = n; f = 0; if(n<i){ if(n == s){ cout << i << endl; } else{ cout << -1 << endl; } judge = false; } else if(n >= i){ for(int j = 0; ;j++){ f += x%i; x = x/i; if(x < i){ f += x; break; } } if(f == s){ cout << i << endl; judge = false; } i++; } } } }
a.cc: In function 'int main()': a.cc:14:16: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and '<unresolved overloaded function type>') 14 | cout << -1 << end; | ~~~~~~~~~~~^~~~~~ In file included from /usr/include/c++/14/istream:41, from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127, from a.cc:1: /usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 116 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | ^~~~~~~~ /usr/include/c++/14/ostream:116:36: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'} 116 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]' 125 | operator<<(__ios_type& (*__pf)(__ios_type&)) | ^~~~~~~~ /usr/include/c++/14/ostream:125:32: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'} 125 | operator<<(__ios_type& (*__pf)(__ios_type&)) | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 135 | operator<<(ios_base& (*__pf) (ios_base&)) | ^~~~~~~~ /usr/include/c++/14/ostream:135:30: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::ios_base& (*)(std::ios_base&)' 135 | operator<<(ios_base& (*__pf) (ios_base&)) | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 174 | operator<<(long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:174:23: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long int' 174 | operator<<(long __n) | ~~~~~^~~ /usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 178 | operator<<(unsigned long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:178:32: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long unsigned int' 178 | operator<<(unsigned long __n) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 182 | operator<<(bool __n) | ^~~~~~~~ /usr/include/c++/14/ostream:182:23: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'bool' 182 | operator<<(bool __n) | ~~~~~^~~ In file included from /usr/include/c++/14/ostream:1022: /usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]' 96 | basic_ostream<_CharT, _Traits>:: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/ostream.tcc:97:22: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short int' 97 | operator<<(short __n) | ~~~~~~^~~ /usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 189 | operator<<(unsigned short __n) | ^~~~~~~~ /usr/include/c++/14/ostream:189:33: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short unsigned int' 189 | operator<<(unsigned short __n) | ~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]' 110 | basic_ostream<_CharT, _Traits>:: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/ostream.tcc:111:20: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'int' 111 | operator<<(int __n) | ~~~~^~~ /usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 200 | operator<<(unsigned int __n) | ^~~~~~~~ /usr/include/c++/14/ostream:200:31: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'unsigned int' 200 | operator<<(unsigned int __n) | ~~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 211 | operator<<(long long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:211:28: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long int' 211 | operator<<(long long __n) | ~~~~~~~~~~^~~ /usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 215 | operator<<(unsigned long long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:215:37: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long unsigned int' 215 | operator<<(unsigned long long __n) | ~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 231 | operator<<(double __f) | ^~~~~~~~ /usr/include/c++/14/ostream:231:25: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'double' 231 | operator<<(double __f) | ~~~~~~~^~~ /usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 235 | operator<<(float __f) | ^~~~~~~~ /usr/include/c++/14/ostream:235:24: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'float' 235 | operator<<(float __f) | ~~~~~~^~~ /usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 243 | operator<<(long double __f) | ^~~~~~~~ /usr/include/c++/14/ostream:243:30: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long double' 243 | operator<<(long double __f) | ~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:301:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 301 | operator<<(const void* __p) | ^~~~~~~~ /usr/include/c++/14/ostream:301:30: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const void*' 301 | operator<<(const void* __p) | ~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:306:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; std::nullptr_t = std::nullptr_t]' 306 |
s812477891
p04016
C++
#include <bits/stdc++.h> using namespace std; int main(){ long int n, s; cin >> n; cin >> s; bool judge = true; long int i ; long int f = 0; long int x; if(s > 1000000){ cout << -1 << endl; continue; } else{ i = 2; } while(judge){ x = n; f = 0; if(n<i){ if(n == s){ cout << i << endl; } else{ cout << -1 << endl; } judge = false; } else if(n >= i){ for(int j = 0; ;j++){ f += x%i; x = x/i; if(x < i){ f += x; break; } } if(f == s){ cout << i << endl; judge = false; } i++; } } }
a.cc: In function 'int main()': a.cc:14:5: error: continue statement not within a loop 14 | continue; | ^~~~~~~~
s227807835
p04016
C++
#include <bits/stdc++.h> using namespace std; int main(){ int n, s; cin >> n; cin >> s; bool judge = true; int i = 2; int f = 0; while(judge){ if(n<i){ if(n == s){ cout << i << endl; } else{ cout << -1 << endl; } judge = false; } else if(n >= i){ for(int j = 0; ;j++){ f += n%i; n = n/i; if(n < i){ f += n; break; } if(f == s){ cout << i << endl; judge = false; } i++; } } }
a.cc: In function 'int main()': a.cc:37:2: error: expected '}' at end of input 37 | } | ^ a.cc:4:11: note: to match this '{' 4 | int main(){ | ^
s320249396
p04016
C++
#include <bits/stdc++.h> using namespace std; int main(){ int n, s; cin >> n; cin >> s; bool judge = true; int i = 2; int f = 0; while(judge){ if(n<i){ if(n == s){ cout << i << endl; } else{ cout << -1 << endl; } judge = false; } else if(n >= i){ for(int j = 0; ;j++){ f += n%i; if(n%i = 0){ break; } n = n/i; } if(f == s){ cout << i << endl; judge = false; } i++; } } }
a.cc: In function 'int main()': a.cc:25:13: error: lvalue required as left operand of assignment 25 | if(n%i = 0){ | ~^~
s913686215
p04016
C++
#include <iostream> #include <cmath> #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef long long int; #define ECHO(v) cout << v << endl; ll f(ll b, ll n){ if(n < b)return n; return f(b, n/b) + n % b; } int main(void){ ll n, s; cin >> n; cin >> s; if(n == s){ cout << n+1 << endl; return 0; } ll sqrtn = sqrt(n); FOR(i, 2, sqrtn){ if(f(i, n)==s){ cout << i << endl; return 0; } } FOR(p, 1, sqrtn){ if((n-s)%p != 0)continue; ll b = 1 + (n-s)/p; if(b == 0)continue; if(f(b, n) == s){ cout << b << endl; printf("%ld", b); return 0; } } cout << -1 << endl; return 0; }
a.cc:8:19: error: declaration does not declare anything [-fpermissive] 8 | typedef long long int; | ^~~
s101048966
p04016
C++
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <map> #include <set> #include <queue> using namespace std; #define lli long long int #define REP(i,n) for(int i=0;i<n;i++) #define REP2(i,n) for(int i=1;i<=n;i++) #define DEBUG 0 lli calc(lli b,lli n){ if(n<b) return n; else return calc(b,n/b)+n%b; } int main(){ lli n,s; cin>>n>>s; if(s>n){ cout<<-1<<endl; return 0; } if(n==s){ cout<<n+1<<endl; return 0; } set<lli> s; for(lli b=2;b*b<=n;b++){ if(calc(b,n)==s){ s.insert(); } } for(lli p=1;p*p<n && p<=s;p++){ lli m = s-p; if(n-m>=0 && (n-m)%p==0){ lli b = (n-m)/p; if(b>p && b>m){ s.insert((n-m)/p); } } } if(s.size())cout<<*s.begin()<<endl; else cout<<-1<<endl; return 0; }
a.cc: In function 'int main()': a.cc:35:18: error: conflicting declaration 'std::set<long long int> s' 35 | set<lli> s; | ^ a.cc:23:15: note: previous declaration as 'long long int s' 23 | lli n,s; | ^ a.cc:38:27: error: request for member 'insert' in 's', which is of non-class type 'long long int' 38 | s.insert(); | ^~~~~~ a.cc:47:35: error: request for member 'insert' in 's', which is of non-class type 'long long int' 47 | s.insert((n-m)/p); | ^~~~~~ a.cc:52:14: error: request for member 'size' in 's', which is of non-class type 'long long int' 52 | if(s.size())cout<<*s.begin()<<endl; | ^~~~ a.cc:52:30: error: request for member 'begin' in 's', which is of non-class type 'long long int' 52 | if(s.size())cout<<*s.begin()<<endl; | ^~~~~
s568186183
p04016
C++
#include <bits/stdc++.h> typedef long long LL; #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; LL dig(LL x, LL n) { if(n<x) return n; else return dig(x/n)+x%n; } int main(void) { LL n,s; cin >> n >> s; vector<LL> f; for(LL i=2; i*i <= n;++i) { if((n-s)%i) continue; f.push_back(i); f.push_back((n-s)/i); } vector<LL> as; for(LL x: f) { if(dig(x,n)==s) as.push_back(x); } sort(as.begin(),as.end()); as.push_back(-1ll); cout << as[0] << endl; return 0; }
a.cc: In function 'LL dig(LL, LL)': a.cc:10:18: error: too few arguments to function 'LL dig(LL, LL)' 10 | else return dig(x/n)+x%n; | ~~~^~~~~ a.cc:8:4: note: declared here 8 | LL dig(LL x, LL n) { | ^~~
s987866120
p04016
C++
#include <bits/stdc++.h> typedef long long LL; #define FOR(i,a,b) for(LL i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; LL dig(LL x, LL n) { if(n<x) return n; else return dig(x/n)+x%n; } int main(void) { LL n,s; cin >> n >> s; vector<LL> f; FOR(i, 1, 1048576) { if((n-s)%i) continue; f.push_back(i); f.push_back((n-s)/i); } vector<LL> as; for(LL x: f) { if(dig(x,n)==s) as.push_back(x); } sort(as.begin(),as.end()); as.push_back(-1ll); cout << as[0] << endl; return 0; }
a.cc: In function 'LL dig(LL, LL)': a.cc:10:18: error: too few arguments to function 'LL dig(LL, LL)' 10 | else return dig(x/n)+x%n; | ~~~^~~~~ a.cc:8:4: note: declared here 8 | LL dig(LL x, LL n) { | ^~~
s831974036
p04016
C++
import math n = int(input()) s = int(input()) if s == 1: print(n) quit() if n == s: print(n+1) quit() def f(b, n): ret = 0 while n > 0: ret += n % b n = n // b return ret for i in range(2, int(math.sqrt(n)+2)): t = f(i, n) if s == t: print(i) quit() for x in range(1, int(math.sqrt(n)+10)): y = s - x if (n-s)%x == 0: b = (n-s)//x if x < b and y < b and x*b+y == n and x+y == s: print(b) quit() print(-1)
a.cc:1:1: error: 'import' does not name a type 1 | import math | ^~~~~~ a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
s144896935
p04016
C++
#include<iostream> #include<map> using namespace std; map<__int64,int> m1; int check(int b,int n){ if(n<b)return n; int s=n%b; n/=b; s+=check(b,n); return s; } int main(){ int i,j,k; int a,n,s; int b,c; int s1=-1; m1[1]=1; map<__int64,int>::iterator itr; cin>>n>>s; a=n-s; for(i=2;i<100000;i++){ if(a==i)break; while(a%i==0){ a/=i; itr=m1.begin(); while(itr!=m1.end()){ b=(*itr).first; b*=i; m1[b]=1; } } } cout<<"OK!"<<endl; itr=m1.begin(); while(itr!=m1.end()){ b=(*itr).first; b++; if(check(b,n)==s){ s1=b; break; } } cout<<s1<<endl; return 0; }
a.cc:4:5: error: '__int64' was not declared in this scope; did you mean '__int64_t'? 4 | map<__int64,int> m1; | ^~~~~~~ | __int64_t a.cc:4:16: error: template argument 1 is invalid 4 | map<__int64,int> m1; | ^ a.cc:4:16: error: template argument 3 is invalid a.cc:4:16: error: template argument 4 is invalid a.cc: In function 'int main()': a.cc:17:11: error: invalid types 'int[int]' for array subscript 17 | m1[1]=1; | ^ a.cc:18:13: error: '__int64' was not declared in this scope; did you mean '__int64_t'? 18 | map<__int64,int>::iterator itr; | ^~~~~~~ | __int64_t a.cc:18:24: error: template argument 1 is invalid 18 | map<__int64,int>::iterator itr; | ^ a.cc:18:24: error: template argument 3 is invalid a.cc:18:24: error: template argument 4 is invalid a.cc:18:36: error: expected initializer before 'itr' 18 | map<__int64,int>::iterator itr; | ^~~ a.cc:25:25: error: 'itr' was not declared in this scope 25 | itr=m1.begin(); | ^~~ a.cc:25:32: error: request for member 'begin' in 'm1', which is of non-class type 'int' 25 | itr=m1.begin(); | ^~~~~ a.cc:26:39: error: request for member 'end' in 'm1', which is of non-class type 'int' 26 | while(itr!=m1.end()){ | ^~~ a.cc:29:35: error: invalid types 'int[int]' for array subscript 29 | m1[b]=1; | ^ a.cc:34:9: error: 'itr' was not declared in this scope 34 | itr=m1.begin(); | ^~~ a.cc:34:16: error: request for member 'begin' in 'm1', which is of non-class type 'int' 34 | itr=m1.begin(); | ^~~~~ a.cc:35:23: error: request for member 'end' in 'm1', which is of non-class type 'int' 35 | while(itr!=m1.end()){ | ^~~
s014662121
p04016
C++
#include <bits/stdc++.h> using namespace std; using ll=long long; using vb=vector<bool>; using vvb=vector<vb>; using vd=vector<double>; using vvd=vector<vd>; using vi=vector<int>; using vvi=vector<vi>; using vl=vector<ll>; using vvl=vector<vl>; using pll=pair<ll,ll>; using tll=tuple<ll,ll>; using vs=vector<string>; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define rep(i,n) range(i,0,n) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define range(i,a,n) for(int i=(a);i<(n);i++) #define LINF ((ll)1ll<<60) #define INF ((int)1<<30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout<<setprecision(a)<<fixed #define fs first #define sc second #define PI (3.1415926535897932384) int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1}; template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;}; template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;} template<class T> void chmax(T &a, const T &b){if(a<b)a=b;} template<class T> void chmin(T &a, const T &b){if(a>b)a=b;} void YN(bool b){cout<<(b?"YES":"NO")<<endl;} void Yn(bool b){cout<<(b?"Yes":"No")<<endl;} void yn(bool b){cout<<(b?"yes":"no")<<endl;} int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,nsub,s,sub; cin>>n>>s; for(ll i=2;i<=sqrt(n);i++){ nsub=n; sub=0; while(i<=nsub){ sub+=(nsub%i); nsub/=i; } sub+=nsub; if(sub==s){ cout<<i<<endl; return 0; } } for(ll i=1;i<sqrt(n);i++){ if((n-s)%i==0){ ll b=(n-s)/i+1; if(sqrt(n)<b<=n){ cout<<b<<endl; return 0; } } } else if(n==s){ cout<<n+1<<endl; return 0; } cout<<-1<<endl; }
a.cc: In function 'int main()': a.cc:66:9: error: 'else' without a previous 'if' 66 | else if(n==s){ | ^~~~
s055817200
p04016
C++
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define se second #define fi first typedef long long ll; using namespace std; const int NUM = 1e5 + 5; const int mod = 998244353; int INF = 2e9; pair <int ,int> pinf = {INF, INF}; ll f (ll b, ll n){ if (n < b) return n; return n % b + f(b, n / b); } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ll n, s; cin >> n >> s; for (ll i = 2; i * i <= n; i++) if (f(i, n) == s){ cout << i; return 0; } ll t = n - s; if (s == 1){ cout << max(n, 2); return 0; } if (t <= 0){ cout << -1; return 0; } for (ll i = 1; i * i <= t; i++){ if (t % i != 0) continue; ll b = i + 1; ll x = t / i; ll y = s - x; if (max(x, y) < b){ cout << b; return 0; } } cout << -1; return 0; }
a.cc: In function 'int main()': a.cc:33:20: error: no matching function for call to 'max(ll&, int)' 33 | cout << max(n, 2); | ~~~^~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:33:20: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 33 | cout << max(n, 2); | ~~~^~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:33:20: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 33 | cout << max(n, 2); | ~~~^~~~~~
s043431926
p04016
C++
#include<iostream> #include<cmath> using namespace std; int shit(int b,int n){ if(n<b) return n; else return shit(b,floor(n/b))+(n%b); } int main(){ long long a,b; cin>>a>>b; if(a==1){ cout<<"-1"; } else if(b==1){ cout<<a; } else if(a==b){ cout<<1; } else if(a<=10000000&&b<=1000000){ for(int i=2;i<=100000;i++){ if(shit(i,a)==b){ cout<<a; break; } else if(i==100000000&&f(i,a)!=b){ cout<<"-1"; } } } else cout<<"-1"; return 0; }
a.cc: In function 'int main()': a.cc:26:47: error: 'f' was not declared in this scope 26 | else if(i==100000000&&f(i,a)!=b){ | ^
s384370497
p04016
C++
#include<iostream> #include<cmath> using namespace std; int shit(int b,int n){ if(n<b) return n else return shit(b,floor(n/b))+(n%b); } int main(){ long long a,b; cin>>a>>b; if(a==1){ cout<<"-1"; } else if(b==1){ cout<<a; } else if(a==b){ cout<<1; } else if(a<=10000000&&b<=1000000){ for(int i=2;i<=100000;i++){ if(shit(i,a)==b){ cout<<a; break; } else if(i==100000000&&f(i,a)!=b){ cout<<"-1"; } } } else cout<<"-1"; return 0; }
a.cc: In function 'int shit(int, int)': a.cc:5:25: error: expected ';' before 'else' 5 | if(n<b) return n | ^ | ; 6 | else return shit(b,floor(n/b))+(n%b); | ~~~~ a.cc: In function 'int main()': a.cc:26:47: error: 'f' was not declared in this scope 26 | else if(i==100000000&&f(i,a)!=b){ | ^
s677308912
p04016
C++
#include <iostream> #include <cmath> using namespace std; int f(int n, int b){ int result = 0; while(n >= b){ result += n % b; n /= b; } result += n; return result; } int main(){ int n, s; int a[16] = {2, 5, 7, 8, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000}; cin >> n >> s; for(int i = 0; i < 16; i++){ if(f(n, a[i]) == s){ cout << i << endl; break; } if(i == 14){ cout << "-1" << endl; } } return 0; }
a.cc: In function 'int main()': a.cc:17:106: error: narrowing conversion of '10000000000' from 'long int' to 'int' [-Wnarrowing] 17 | int a[16] = {2, 5, 7, 8, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000}; | ^~~~~~~~~~~ a.cc:17:119: error: narrowing conversion of '100000000000' from 'long int' to 'int' [-Wnarrowing] 17 | int a[16] = {2, 5, 7, 8, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000}; | ^~~~~~~~~~~~
s015338087
p04016
C++
#include "iostream" #include "algorithm" #include "string" #include "vector" #include "cmath" #include "bitset" #include "queue" #include "functional" #include "map" #include "unordered_map" #include "set" #include "stack" #define lp(n) for (int i = 0; i < n; i++) #define LP(n,i) for (int i = 0; i < n; i++) #define mod 1000000007 #define sp ' ' #define intmax 2147483647 #define llmax 9223372036854775807 #define nyan "(=^・ω・^=)" typedef long long ll; using namespace std; ll n,s; ll f(ll x, ll y){ if(x==0)return 0; return x%y+f(x/y,y); } int main(){ cin>>n>>s; if(s>n){ cout<<-1<<endl; return 0 } if(s==n){ cout<<n+1<<endl; return 0; } for(ll i=2;i*i<=n;i++){ if(f(n,i)==s){ cout<<i<<endl; return 0; } } for(ll i=sqrt(n)+1;i>=1;i--){ if((n-s)/i+1!=1&&f(n,(n-s)/i+1)==s){ cout<<(n-s)/i+1<<endl; return 0; } } cout<<-1<<endl; return 0; }
a.cc: In function 'int main()': a.cc:35:17: error: expected ';' before '}' token 35 | return 0 | ^ | ; 36 | } | ~
s689729931
p04016
C++
#include<bits/stdc++.h> #define int long long using namespace std; long long tmp; long long trans(long long b,long long n){ if(n<b){ return n; } return trans(b,n/b)+n%b; } vector<long long> divi; signed main(){ long long n,s; cin>>n>>s; tmp=n; if(s==1){ cout<<n; return 0; } long long k=sqrt(n); for(int i=2;i*i<=n;i++){ if(trans(i,tmp)==s){ cout<<i; return 0; } else{ tmp=n;q } } if(s>n){ cout<<"-1"; return 0; } for(int i=1;i*i<=n-s;i++){ if((n-s)%i==0){ divi.push_back(i); divi.push_back((n-s)/i); if(i*i==(n-s)){ divi.pop_back(); } } } sort(divi.begin(),divi.end()); for(int i=0;i<divi.size();i++){ if((divi[i]+1)*(divi[i]+1)>n&&trans(divi[i]+1,n)==s&&(n-s)/(divi[i])<divi[i]+1){ cout<<divi[i]+1; return 0; } } cout<<"-1"; return 0; }
a.cc: In function 'int main()': a.cc:27:31: error: 'q' was not declared in this scope 27 | tmp=n;q | ^
s638090020
p04016
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,s,sq; bool check(ll b) { ll ret=0,t=n; for(;t;t/=b) ret+=t%b; return (ret==s); } ll solve() { if(s==n) return n+1; if(s>n) return -1; for(ll i=2;i*i<=n;i++) if(check(i)) return i; for(ll i=1;i*i<=n;i++) if((n-s)%i==0&&check((n-s)/i+1)) return ((n-s)/i+1); return -1; } int main() { scanf("%lld%lld",&n,&s);s printf("%lld",solve()); return 0; }
a.cc: In function 'int main()': a.cc:28:34: error: expected ';' before 'printf' 28 | scanf("%lld%lld",&n,&s);s | ^ | ; 29 | printf("%lld",solve()); | ~~~~~~
s616557339
p04016
C++
// D. #include <iostream> #include <algorithm> #include <sstream> #include <cstdio> #include <cstdlib> using namespace std; typedef long long LL; LL check(LL b, LL n) { LL c = 0; while (n) { c += n % b; n /= b; } return c; } int main(int argc, char *argv[]) { LL n, s; cin >> n >> s; LL ans = 1LL << 60; if (s == 1LL) { ans = n; } for (LL b = 2; b <= 10000; ++b) { if (check(b, n) == s) { ans = min(ans, b); } } for (LL d = 2; d <= 5; ++d) { LL q = (LL)pow(n, 1.0 / d); for (LL b = max(2LL, q - 100); b <= q + 100; ++b) { if (check(b, n) == s) { ans = min(ans, b); } } } cout << (ans == (1LL << 60) ? -1 : ans) << endl; return 0; }
a.cc: In function 'int main(int, char**)': a.cc:34:28: error: 'pow' was not declared in this scope 34 | LL q = (LL)pow(n, 1.0 / d); | ^~~
s866988607
p04016
C++
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <queue> #include <functional> using namespace std; long long f(long long b, long long n) { if (n < b)return n; else return f(b, n / b) + n % b; } int main() { long long n, s; cin >> n >> s; //n = 1e11; /*for (int b = 2; b <= n; b++) { cerr << b << " " << f(b, n) << endl; }*/ if ((n+1)/2 < s)cout << -1 << endl; else { long long ans = n; long long x = 2; for(int i=1;i<=sqrt(n);i++){ long long y = n / i; long long z = f(y, n); if (z > s)continue; if ((s - z) % i)continue; long long tmp = y - (s - z) / i; if (tmp < n / (i + 1))continue; ans = min(ans, tmp); } for (int i = 2; i<=sqrt(n); i++) { long long y = i; if (f(y, n) == s)ans = min<long long>(ans, i); } cout << ans << endl; } return 0; }
a.cc: In function 'int main()': a.cc:25:32: error: 'sqrt' was not declared in this scope 25 | for(int i=1;i<=sqrt(n);i++){ | ^~~~ a.cc:36:36: error: 'sqrt' was not declared in this scope 36 | for (int i = 2; i<=sqrt(n); i++) { | ^~~~
s614894186
p04016
C++
#include <cstdio> #include <cmath> using namespace std; long long N, S; double n; long long function(long long b, long long n) { if (n < b) { return n; } else { return function(b, n/b) + n % b; } } long long solve() { if (N < S) { return -1; } if (N == S) { return N+1; } for (long long i = 2; i < n+1; i++) { if (function(i, N) == S) { return i; } } for (long long p = (long long)(n+1); p >= 1; p--) { if ((N-S)/p == 0) { continue; } if (N % p == S % p && function((N-S)/p + 1, N) == S) { return (N-S)/p+1; } } return -1; }
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s029349381
p04016
C++
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #define REP(i,n) for(int (i)=0;(i)<(n);(i)++) constexpr long MOD = 1e9 + 7; using namespace std; long digitsum(long b, long n) { if (n < b) return n; else return digitsum(b, n / b) + n % b; } int main() { long n, s; cin >> n >> s; if (s == n) { cout << n + 1 << endl; return 0; } if (n < s) { cout << -1 << endl; return 0; } for (int i = 2; i < sqrt(n) + 1; i++) { if (digitsum(i, n) == s) { cout << i << endl; return 0; } } long minb = LONG_MAX; for (int i = 1; i < sqrt(n); i++) { long b = (n - s) / i + 1; if (digitsum(b, n) == s) { minb = min(minb, b); } } if (minb != LONG_MAX) { cout << minb << ":" << endl; } else { cout << -1 << endl; } }
a.cc: In function 'int main()': a.cc:36:17: error: 'LONG_MAX' was not declared in this scope 36 | long minb = LONG_MAX; | ^~~~~~~~ a.cc:5:1: note: 'LONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 4 | #include <cmath> +++ |+#include <climits> 5 | #define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
s112438323
p04016
C++
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll digit_sum(ll i, ll b) { ll ans = 0; while (i > 0) { ans += i % b; i /= b; } return ans; } int main() { ll n, s; cin >> n >> s; ll lim = sqrt(n); ll ans = n + 1; for (ll b = 2; b < lim; b++) { if (digit_sum(n, b) == s) { ans = min(ans, b); } } if (lim * lim == s) lim--; for (ll p = 1; p < lim; p++) { const ll b = n / p; const ll q = n - b * p; if (p + q == s) { ans = min(ans, b); } } if (ans == n + 1) { cout << -1 << endl; } else { cout << ans << endl; } }
a.cc: In function 'int main()': a.cc:24:14: error: 'sqrt' was not declared in this scope 24 | ll lim = sqrt(n); | ^~~~
s387569261
p04016
C++
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; ll digit_sum(ll i, ll b) { ll ans = 0; while (i > 0) { ans += i % b; i /= b; } return ans; } int main() { ll n, s; cin >> n >> s; ll lim = sqrt(n); ll ans = n + 1; for (ll b = 2; b < lim; b++) { if (digit_sum(n, b) == s) { ans = min(ans, b); } } if (lim * lim == s) lim--; for (ll p = 1; p < lim; p++) { const ll b = n / p; const ll q = n - b * p; if (p + q == s) { ans = min(ans, b); } } if (ans == n + 1) { cout << -1 << endl; } else { cout << ans << endl; } }
a.cc: In function 'int main()': a.cc:24:14: error: 'sqrt' was not declared in this scope 24 | ll lim = sqrt(n); | ^~~~
s303773806
p04016
C++
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define rep(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--) #define rrep(i,n) RFOR(i,n,0) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = 1e18; ll f(ll b,ll n){ if(n<b) return n; return f(b, n/b) + n%b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n,s; cin >> n >> s; if(s == n){ cout << (n+1) << endl; return 0; } for(ll b = 2; b*b <=n; b++){ if(f(b,n) == s){ cout << b << endl; return 0; } } ll ans = INF for(ll p = 1; p*p <= n; p++){ if((n - s) % p != 0) continue; ll b = (n - s) / p + 1; if(b < 2) continue; if(f(b,n) == s) ans = min(ans,b); } cout << (ans == INF ? -1 : ans) << endl; }
a.cc: In function 'int main()': a.cc:42:9: error: expected ',' or ';' before 'for' 42 | for(ll p = 1; p*p <= n; p++){ | ^~~ a.cc:42:23: error: 'p' was not declared in this scope 42 | for(ll p = 1; p*p <= n; p++){ | ^
s951718391
p04016
C++
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define rep(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--) #define rrep(i,n) RFOR(i,n,0) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = 1e18 ll f(ll b,ll n){ if(n<b) return n; return f(b, n/b) + n%b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n,s; cin >> n >> s; if(s == n){ cout << (n+1) << endl; return 0; } for(ll b = 2; b*b <=n; b++){ if(f(b,n) == s){ cout << b << endl; return 0; } } ll ans = INF for(ll p = 1; p*p <= n; p++){ if((n - s) % p != 0) continue; ll b = (n - s) / p + 1; if(b < 2) continue; if(f(b,n) == s) ans = min(ans,b); } cout << (ans == INF ? -1 : ans) << endl; }
a.cc:15:1: error: expected ',' or ';' before 'll' 15 | ll f(ll b,ll n){ | ^~ a.cc: In function 'int main()': a.cc:34:20: error: 'f' was not declared in this scope 34 | if(f(b,n) == s){ | ^ a.cc:42:9: error: expected ',' or ';' before 'for' 42 | for(ll p = 1; p*p <= n; p++){ | ^~~ a.cc:42:23: error: 'p' was not declared in this scope 42 | for(ll p = 1; p*p <= n; p++){ | ^
s496087561
p04016
C++
/* *** In The Name of God ... *** */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define int long long #define all(v) v.begin() , v.end() template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;} template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;} int n , s ; int f ( int n , int b ) { if ( b == 1 ) return 4e18 ; int ret = 0 ; while ( n ) { ret += ( n % b ) ; n /= b ; } return ret ; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s ; int res = 4e18 ; for ( int i = 2 ; i <= 2e6 ; ++ i ) if ( f ( n , i ) == s ) smin ( res , i ) ; if ( s == 1 ) return cout << n << '\n' , 0 ; if ( s == n ) return cout << s + 1 << '\n' , 0 ; if ( s > n ) return cout << -1 << '\n' , 0 ; int t = n - s ; for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) { if ( t % possible == 0 ) { if ( f ( n , possible + 1 ) == s ) smin ( res , possible + 1 ) ; if ( f ( n , ( t / possible ) + 1 ) == s ) smin ( res , ( t / possible ) + 1 ) ; } } if ( res == 4e18 ) res = -1 ; cout << res << '\n' ; }
a.cc: In function 'int32_t main()': a.cc:43:50: error: no matching function for call to 'min(double, long long int&)' 43 | for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) { | ~~~~^~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:2: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:43:50: note: deduced conflicting types for parameter 'const _Tp' ('double' and 'long long int') 43 | for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) { | ~~~~^~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:43:50: note: mismatched types 'std::initializer_list<_Tp>' and 'double' 43 | for ( int possible = 1 ; possible <= min ( 1LL * 2e6 , t ) ; ++ possible ) { | ~~~~^~~~~~~~~~~~~~~~~
s435310065
p04016
C++
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> /* //#if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> */ // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> /* //#if __cplusplus >= 201103L #include <array> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> */ using namespace std; #define fi first #define se second #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb(s) push_back(s) #define mmax(x,y) (x>y?x:y) #define mmin(x,y) (x<y?x:y) #define maxch(x,y) x=mmax(x,y) #define minch(x,y) x=mmin(x,y) #define mp(a,b) make_pair(a,b) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #define uni(x) x.erase(unique(all(x)),x.end()) template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;} template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;} #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) > (b) ? (b) : (a)) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<P, int> PPI; #define INF INT_MAX/3 #define MAX_N 1000 #define M_INF 1000000000 int func(int n,int mod){ if(n < mod) return n; return func(n/mod,mod) + n % mod; } signed main(){ int n,s; cin>>n>>s; if(n == s){ cout<<n+1<<endl; return 0; } for(int i=2;i<=1e6;i++){ if(func(n,i) != s) continue; cout<<i<<endl; return 0; } int ans = INF; for(int i=1;i<=1e6;i++){ int b = (n-s+i)/i; if(b <= 1 || func(n,b) != s) continue; Min(ans,b); } if(ans == INF) ans = -1; cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:137:5: error: 'Min' was not declared in this scope; did you mean 'sin'? 137 | Min(ans,b); | ^~~ | sin
s025811151
p04016
C++
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <sstream> #include <functional> #include <map> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <deque> #include <set> #include <list> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> P; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const ll INF = 1LL<<59; const ll mod = 1e9+7; #define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i)) #define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d)) #define all(v) (v).begin(), (v).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset((m),(v),sizeof(m)) #define chmin(X,Y) ((X)>(Y)?X=(Y),true:false) #define chmax(X,Y) ((X)<(Y)?X=(Y),true:false) #define fst first #define snd second #define UNIQUE(x) (x).erase(unique(all(x)),(x).end()) template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;} int main(){ ll n, s; cin>>n>>s; for(ll b = 2; b*b<=n; b++){ ll r = 0, m = n; while(m){ r += m%b; m /= b; } if(r==s){ cout<<b<<endl; return 0; } } ll res = INF; if(s==n) res = n+1; if(s==1) res = max(n, 2); for(ll i = 1; i<=s; i++){ ll b = (n-s+i)/i; if(b<=sqrt(n)) break; if(n/b+n%b!=s) continue; res = min(res, b); } if(res==INF) res = -1; cout<<res<<endl; return 0; }
a.cc: In function 'int main()': a.cc:57:27: error: no matching function for call to 'max(ll&, int)' 57 | if(s==1) res = max(n, 2); | ~~~^~~~~~ In file included from /usr/include/c++/14/algorithm:60, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:57:27: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 57 | if(s==1) res = max(n, 2); | ~~~^~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:57:27: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 57 | if(s==1) res = max(n, 2); | ~~~^~~~~~
s659952816
p04016
C++
#include <bits/stdc++.h> using namespace std; /*{{{*/ //template #define rep(i,n) for(int i=0;i<n;i++) constexpr int INF = numeric_limits<int>::max()/2; constexpr long long LINF = numeric_limits<long long>::max()/3; #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define all(v) (v).begin(),(v).end() #define sz(x) (int)(x).size() #define debug(x) cerr<<#x<<":"<<x<<endl #define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl //struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double{ double d; explicit Double(double x) : d(x){} }; ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; } template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; } template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; } template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; } template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; } template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; } typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); } //constexpr double eps = 1e-14; constexpr double eps = 1e-10; constexpr ll mod = 1e9+7; const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1}; /*}}}*/ ll f(ll b,ll n){ if(n<b) return n; else return f(b,(n/b)) + (n % b); } // sq(n) <= sqrt(n) ll sq(ll n){ for(ll i=1;i<n;i++){ if(i*i>n) return i-1; } return -1; } int main(){ ll n,s; cin >> n >> s; ll sqn = sq(n); for(ll i=2;i<=min(sqn,1000000);i++){ if(f(i,n)==s){ cerr <<"shigure" << endl; cout << i << endl; return 0; } } if(n < s){ cout << -1 << endl; return 0; } ll sqns = sq(n-s); for(ll x=sqns;x>0;x--){ if((n-s)%x) continue; ll b = (n-s)/x + 1; ll y = s-x; if(b<2) continue; if(b > sqn and x < b and y>=0 and y<b){ cerr << "yuudachi" << endl; cout << b << endl; return 0; } } if(s == n){ cout << n+1 << endl; return 0; } cout << -1 << endl; return 0; }
a.cc: In function 'int main()': a.cc:55:22: error: no matching function for call to 'min(ll&, int)' 55 | for(ll i=2;i<=min(sqn,1000000);i++){ | ~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:55:22: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 55 | for(ll i=2;i<=min(sqn,1000000);i++){ | ~~~^~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:55:22: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 55 | for(ll i=2;i<=min(sqn,1000000);i++){ | ~~~^~~~~~~~~~~~~
s918304533
p04016
C++
#include <map> #include <algorithm> #include <cassert> #include <climits> #include <complex> #include <cstdio> #include <string> #include <iostream> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long; using ld = long double; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define bit(n, i) (((n) >> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) #define DEBUG(X) cerr<<" "<<#X<<" = "<<X<<endl; #define DUMP(A, n) for (auto x=begin(A); x!=begin(A)+n;x++){cout <<*x<< ' ';} cout<<endl; #define DUMPP(A, n, m) for (auto x=begin(A); x != begin(A)+n;x++) {for (auto y=begin(*x); y != begin(*x)+m;)cout <<*y++<< ' '; cout<<endl;}; #define DUMPM(M) for (auto itr=mp.begin(); itr!=mp.end(); itr++) {cout<<itr->first<<" -> "<<itr->second<<endl;} #define FOR(i,x,y) for(int i=(x);i<(int)(y);i++) #define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++) #define REP(i,y) for(int i=0;i<(int)(y);i++) #define REPP(i,y) for(int i=1;i<=(int)(y);i++) #define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--) ll n,s; ll f(ll b, ll n) { if (n >= b) return (n%b) + f(b, (ll)(n/b)); else return n; } int main() { cin >> n >> s; ll nr = sqrt(n); for(ll b=2;b<=nr;b++) { ll sum = f(b, n); if (sum==s) { cout << b << endl; return 0; } } if (s==n) { cout << n+1 << endl; return 0; } if (n<s) { cout << "-1" << endl; return 0; } for(ll p=1;p<=9;p++) { ll q = s-p; if ((n-q)%p==0&&b>=q&&q>=0) { ll b = (n-q)/p; cout << b << endl; return 0; } } cout << "-1" << endl; return 0; }
a.cc: In function 'int main()': a.cc:68:21: error: 'b' was not declared in this scope 68 | if ((n-q)%p==0&&b>=q&&q>=0) { | ^ a.cc:69:10: error: redeclaration of 'll b' 69 | ll b = (n-q)/p; | ^ a.cc:68:21: note: '<typeprefixerror>b' previously declared here 68 | if ((n-q)%p==0&&b>=q&&q>=0) { | ^
s098716610
p04016
C++
#include <bits/stdc++.h> #define MaxN 100005 using namespace std; long long S,N,ans; int main() { cin>>N>>S; ans=N; for(long long i=2;i*i<=N;i++) { int X=N,sum=0; while(X) { sum+=X%i; X=X/i; } if(S==sum) { cout<<i; return 0; } } for(long long i=1;i*i<=(N-S);i++) { long long j; if((N-S)%i==0) j=(N-S)/i; int X=N,sum=0; while(X) { sum+=X%j; X=X/j; } if(S==sum) { ans=min(ans,j); } } if(ans==N) { if(s==1) cout<<ans; else cout<<-1; } else cout<<ans; return 0; }
a.cc: In function 'int main()': a.cc:44:12: error: 's' was not declared in this scope 44 | if(s==1) | ^
s516701950
p04016
C++
#include <bits/stdc++.h> #define MaxN 100005 using namespace std; long long S,N,ans; int main() { cin>>N>>S; ans=N; for(int i=2;i*i<=N;i++) { int X=N,sum=0; while(X) { sum+=X%i; X=X/i; } if(S==sum) { cout<<i; return 0; } } for(int i=2;i*i<=(N-S);i++) { int j; if((N-S)%i==0) j=(N-S)/i; int X=N,sum=0; while(X) { sum+=X%j; X=X/j; } if(S==sum) { ans=min(ans,j); } } if(ans==N) { cout<<-1; } else cout<<ans; return 0; }
a.cc: In function 'int main()': a.cc:39:20: error: no matching function for call to 'min(long long int&, int&)' 39 | ans=min(ans,j); | ~~~^~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:39:20: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 39 | ans=min(ans,j); | ~~~^~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:39:20: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 39 | ans=min(ans,j); | ~~~^~~~~~~
s305006583
p04016
C++
// MAGRANT - GNC19 - TEMPLATE 3.2 // 2017/8/22 - AtCoder Regular Contest 060 - D // PRACTISING TIME TAGS: // ALGORITHM: ##MIN, STARTED AT: // CODING: ##MIN, STARTED AT: // SUMMARY: [MISTAKES / REQUISITES] // FOR COMPATIBILITY: #define _CRT_SECURE_NO_WARNINGS // UNIVERSAL DEFINITIONS: #define N (1<<17) #define MODULO (1000000007) #define HA1 (2420609) #define HA2 (19260817) // FREQUENT HEADER FILES: #include <cstdio> #include <iostream> #include <fstream> #include <sstream> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <algorithm> #include <stack> #include <vector> #include <set> #include <map> #include <deque> #include <queue> #include <complex> using namespace std; // TEMPLATE BEGINS HERE. //#define MAGRANT_ALLOWS_CTMP // IMPORTANT: DO NOT OPEN UNLESS AS CONTESTANT. // CAUTION: BEWARE OF CONFLICT. #ifdef MAGRANT_ALLOWS_CTMP namespace CTMP { // ELEMENTARY MATHEMATICAL COMPUTATIONS: long long fact[N], inv[N]; long long KissMe(long long xx, long long yy) { if (yy == 0LL) { return 1LL; } long long Res = KissMe((xx*xx) % (long long)MODULO, yy >> 1); if (yy % 2LL == 1LL) { Res *= xx; Res %= (long long)MODULO; } return Res; } inline void InitFactInv() { fact[0] = 1LL; for (int i = 1;i < N - 4;i++) { fact[i] = fact[i - 1] * (long long)i; fact[i] %= (long long)MODULO; } inv[N - 5] = KissMe(fact[N - 5], (long long)(MODULO - 2)); for (int i = N - 6;i >= 0;i--) { inv[i] = inv[i + 1] * (long long)(i + 1); inv[i] %= (long long)MODULO; } } inline long long Choose(int xx, int yy) { if (xx < yy) { return 0LL; } else if (xx == yy) { return 1LL; } long long Res = fact[xx]; Res *= inv[yy]; Res %= (long long)MODULO; Res *= inv[xx - yy]; Res %= (long long)MODULO; return Res; } inline long long GridWays(int fx, int fy, int sx = 0, int sy = 0) { fx -= sx, fy -= sy; if (fx < 0 || fy < 0) { return 0LL; } long long Res = fact[fx + fy]; Res *= inv[fx]; Res %= (long long)MODULO; Res *= inv[fy]; Res %= (long long)MODULO; return Res; } } #endif // TEMPLATE FINISHES HERE. long long n, s; int main() { // IMPORTANT: DO NOT OPEN UNLESS AS CONTESTANT. // CAUTION: BEWARE OF CONFLICT. //using namespace CTMP; // REAFFIRM THE FOLLOWING BEFORE CODING. // 1. THE ALGORITHM IS CORRECT. // 2. THE COMPLEXITY IS PROPER. // 3. THE ALGORITHM CANNOT BE SIMPLER. // 4. CODING DETAILS WERE CONSIDERED. scanf("%lld%lld", &n, &s); for (int i = 2;(long long)i*(long long)i <= n;i++) { long long tmp = n; long long res = 0LL; while (tmp > 0LL) { res += (tmp%i); tmp /= i; } if (res == s) { printf("%d\n", i); //system("pause"); return 0; } } long long rt = n - s; long long Ans = LLONG_MAX; for (int i = 1;(long long)i*(long long)i <= rt;i++) { if (rt % (long long)i == 0LL) { long long tb1 = (long long)i; tb1++; if ((n / tb1) + (n%tb1) == s && (n / tb1) < tb1) { Ans = min(Ans, tb1); } long long tb2 = rt / (long long)i; tb2++; if ((n / tb2) + (n%tb2) == s && (n / tb2) < tb2) { Ans = min(Ans, tb2); } } } if (Ans == LLONG_MAX) { printf("-1\n"); } else { printf("%lld\n", Ans); } // REAFFIRM THE FOLLOWING BEFORE SUBMITTING. // 1. THE ARRAYS ARE IN PROPER SIZE. // 2. THE CORNER CASES WILL NOT LEAD TO VIOLATION. // 3. NO TYPO LIKE N->M EXISTS. // 4. THE INPUT/OUTPUT IS IN THE SPECIFIED FORMAT. // 5. ALL CATEGORIES DO NOT INTERSECT. //system("pause"); return 0; }
a.cc: In function 'int main()': a.cc:142:25: error: 'LLONG_MAX' was not declared in this scope 142 | long long Ans = LLONG_MAX; | ^~~~~~~~~ a.cc:35:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 34 | #include <complex> +++ |+#include <climits> 35 | using namespace std;
s790449248
p04016
C++
if(s == 1){ cout << n << endl; return 0; }else if(s > n){ cout << -1 << endl; return 0; }else if(s == n){ cout << n+1 << endl; return 0; }else{ lli sn = int(sqrt(n))+1; for(lli i = 2; i<=sn; i++) if(f(i,n) == s){ cout << i << endl; return 0; } for(lli i = sn; i >= 1; i--) if(s>=i && (n-(s-i))%i == 0 && s-i <= (n-(s-i))/i - 1){ cout << (n-(s-i))/i << endl; return 0; } cout << -1 << endl; return 0; } return 0; }
a.cc:2:9: error: expected unqualified-id before 'if' 2 | if(s == 1){ | ^~ a.cc:5:10: error: expected unqualified-id before 'else' 5 | }else if(s > n){ | ^~~~ a.cc:8:10: error: expected unqualified-id before 'else' 8 | }else if(s == n){ | ^~~~ a.cc:11:10: error: expected unqualified-id before 'else' 11 | }else{ | ^~~~ a.cc:26:9: error: expected unqualified-id before 'return' 26 | return 0; | ^~~~~~ a.cc:27:1: error: expected declaration before '}' token 27 | } | ^
s026390058
p04016
C++
#include <iomanip> #include <string> #include <vector> #include <queue> #include <algorithm> #include <utility> #include <cmath> #include <map> #include <set> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> #include <random> #include <deque> #define INF_LL 1e18 #define INF 1e9 #define REP(i, n) for(int i = 0;i < (n);i++) #define FOR(i, a, b) for(int i = (a);i < (b);i++) #define all(x) x.begin(),x.end() using namespace std; using ll = long long; using PII = pair<int, int>; using PLL = pair<ll, ll>; const ll MOD = 1e9+7; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; template<typename T> void chmax(T &a, T &b){ a = max(a, b); } template<typename T> void chmin(T &a, T &b){ a = min(a, b); } class Union_find{ private: vector<int> par; vector<int> rank; int n; public: Union_find(int a){ n = a; for(int i = 0;i < n;i++){ par.push_back(i); rank.push_back(0); } } int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; }else{ par[y] = x; if(rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y){ return find(x) == find(y); } }; class RMQ{ int n; vector<int> dat; public: RMQ(int n_){ n = 1; while(n < n_) n *= 2; REP(i, n*2-1){ dat.push_back(INF); } } void update(int x, int i){ i += n-1; dat[i] = x; while(i > 0){ i = (i-1)/2; dat[i] = min(dat[i*2+1], dat[i*2+2]); } } int query(int a, int b, int l, int r, int x){ if(a <= l && r <= b) return dat[x]; if(r <= a || b <= l) return INF; int res = INF; res = min(query(a, b, l, (l+r)/2, x*2+1), query(a, b, (l+r)/2, r, x*2+2)); return res; } int query(int a, int b){ return query(a, b, 0, n, 0); } }; const ll mod = 1e9+7; ll f(ll b, ll n){ ll sum = 0; while(n > 0){ sum += n%b; n = n/b; } return sum; } int main(void){ ll n, s; cin >> n >> s; if(n == s){ cout << n+1 << endl; return 0; } ll ans = INF_LL; for(int i = 2;i <= sqrt(n);i++){ if(f(i, n) == s){ ans = min(ans, (ll)i); } } for(int i = 1;i < sqrt(n);i++){ ll b = (n-s)/i+1; if(f(b, n) == s){ ans = min(ans, b); } } cout << (ans == INF_LL ? -1 : ans) << endl; }
a.cc: In function 'int main()': a.cc:133:9: error: 'cin' was not declared in this scope 133 | cin >> n >> s; | ^~~ a.cc:15:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>' 14 | #include <random> +++ |+#include <iostream> 15 | #include <deque> a.cc:135:17: error: 'cout' was not declared in this scope 135 | cout << n+1 << endl; | ^~~~ a.cc:135:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>' a.cc:150:9: error: 'cout' was not declared in this scope 150 | cout << (ans == INF_LL ? -1 : ans) << endl; | ^~~~ a.cc:150:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
s396630247
p04016
C++
#include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <array> #include <string> #include <vector> #include <algorithm> #include <functional> #define MOD 1000000007 #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i<N;++i) typedef long long int LL; LL n, s; LL ans; bool f(LL b) { LL sum = 0, n_copy = n; while (n_copy) { sum += n_copy % b; n_copy /= b; } return (sum == s ? true : false); } int main() { in >> n >> s; if (n == s) { out << n + 1 << std::endl; return 0; } for (LL i = 2; i <= std::sqrt(n); ++i) { if (f(i) == true) { out << i << std::endl; return 0; } } ans = n + 1; for (LL i = 1; i <= std::sqrt(n); ++i) { LL res = (n - s) / i + 1; if (res > 1 && f(res) == true) { ans = std::min(ans, res); } } if (ans == n + 1) { out << -1 << std::endl; } else { out << ans << std::endl; } return 0; }
a.cc: In function 'int main()': a.cc:40:34: error: 'sqrt' is not a member of 'std'; did you mean 'sort'? 40 | for (LL i = 2; i <= std::sqrt(n); ++i) | ^~~~ | sort a.cc:49:34: error: 'sqrt' is not a member of 'std'; did you mean 'sort'? 49 | for (LL i = 1; i <= std::sqrt(n); ++i) | ^~~~ | sort
s936453562
p04016
C++
#include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <array> #include <string> #include <vector> #include <algorithm> #include <functional> #define MOD 1000000007 #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i<N;++i) typedef long long int LL; LL n, s; LL ans; bool f(LL b) { LL sum = 0, n_copy = n; while (n_copy) { sum += n_copy % b; n_copy /= b; } return (sum == s ? true : false); } int main() { in >> n >> s; if (n == s) { out << n + 1 << std::endl; return 0; } for (LL i = 2; i <= sqrt(n); ++i) { if (f(i) == true) { out << i << std::endl; return 0; } } ans = n + 1; for (LL i = 1; i <= sqrt(n); ++i) { LL res = (n - s) / i + 1; if (res > 1 && f(res) == true) { ans = std::min(ans, res); } } if (ans == n + 1) { out << -1 << std::endl; } else { out << ans << std::endl; } return 0; }
a.cc: In function 'int main()': a.cc:40:29: error: 'sqrt' was not declared in this scope 40 | for (LL i = 2; i <= sqrt(n); ++i) | ^~~~ a.cc:49:29: error: 'sqrt' was not declared in this scope 49 | for (LL i = 1; i <= sqrt(n); ++i) | ^~~~
s693888061
p04016
Java
arc060; import static java.lang.Math.*; import java.util.Arrays; import java.util.Scanner; /** * http://arc060.contest.atcoder.jp/tasks/arc060_b * f(b,n) は、n を b 進表記したときの各桁の和 * f(b,n)=s を満たすような 2 以上の整数 b が存在するか判定(存在する場合は最小のb) * * @author Cummin */ /** * 例: b=10の場合、123=1*100+2*10+3 ⇒ 1*(99+1)+2(9+1)+3=9*(1*11+2*1)+(1+2+3) * b進法の場合、ABC=A*b^2+B*b+C ⇒ ABC=(b-1)*x + y * ここで、ABC=n, y=sだから、(n-s)=(b-1)*x であり、(n-s)を素因数分解して一番小さい約数が(b-1) */ public class Main { public static void main(String[] args) { long N, S ; Scanner sc = new Scanner(System.in); N = sc.nextLong(); S = sc.nextLong(); long ans = -1 ; if (N==S) { ans = N+1 ; } else if (N<S) { ans = -1 ; } else if (S==1) { ans = N ; } else { long factors[][] ; // 10^9 では、素因数の数は高々15個未満 factors = prime_factors(N-S) ; long combi[] ; long list[] ={1}; for (int i=0 ; factors[i][1]>0 ; i++){ combi = expand(factors[i][0],factors[i][1]) ; list = direct_product(list, combi) ; } Arrays.sort(list) ; ans = -1 ; for (int i=1 ; i<list.length ; i++){ if (f(list[i]+1,N)==S) { ans = list[i]+1 ; break ; } } } if (ans<2) ans = -1 ; System.out.println(ans) ; } static long[] expand(long a, long b) { // a^b long ans[] = new long[(int)b+1] ; ans[0] = 1 ; for (int i=1 ; i<(b+1); i++){ ans[i] = ans[i-1] * a ; // System.out.printf("%d ", ans[i]) ; } // System.out.println() ; return ans ; } static long[] direct_product(long[] A, long[] B) { // A × B long ans[] = new long[A.length * B.length] ; for (int i=0 ; i<B.length; i++) { for (int j=0 ; j<A.length; j++) { ans[i*A.length+j] = A[j] * B[i] ; // System.out.printf("%d ", ans[i*A.length+j]) ; } } // System.out.println() ; return ans ; } ////////////////// 素因数分解 ///////////////////// static long[][] prime_factors(long N) { int M ; M = (int) Math.sqrt(N) + 1 ; if (M<30) M=30 ; int prime[] = new int[M / 2]; int prime_cnt ; prime_cnt = get_prime_list(M, prime) ; long factors[][] =new long[15][2] ; // 10^9 では、素因数の数は高々15個未満 int fct_cnt = 0 ; for (int i= 1 ; i < prime_cnt ; i++) { if ((N % prime[i])==0) { factors[fct_cnt][0] = prime[i] ; factors[fct_cnt][1] = 1 ; fct_cnt ++ ; N = N / prime[i] ; while ((N % prime[i])==0) { factors[fct_cnt-1][1] ++ ; N = N / prime[i] ; } } } if (N!=1) { factors[fct_cnt][0] = N ; factors[fct_cnt][1] = 1 ; fct_cnt ++ ; } /** / for (int i= 0 ; i<fct_cnt ; i++) { System.out.printf("prime= %d, cnt=%d \n", factors[i][0], factors[i][1]) ; } System.out.println() ; /**/ return factors ; } //////////////// Prime Listの生成 //////////////////// static int digit_2[] = {0x01, 0x02, 0x04, 0x08, 0x010, 0x020, 0x040, 0x080, 0x0100, 0x0200, 0x0400, 0x0800, 0x01000, 0x02000, 0x04000, 0x08000, 0x010000, 0x020000, 0x040000, 0x080000, 0x0100000, 0x0200000, 0x0400000, 0x0800000, 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x010000000, 0x020000000}; static int get_prime_list(int N, int prime[]) { int Bit[] = new int[N / 30 + 1] ; int _30m_d = 0x0efbaebbe; Arrays.fill(Bit, _30m_d); Bit[0] = Bit[0] & 0xFFFFFFE9; int t_prime[] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; int p_pos = 11; for (int i = 0; i < p_pos; i++) { prime[i] = t_prime[i]; } int pos = 4; for (int ii = pos; ii < p_pos; ii++) { int p; p = prime[ii]; for (int j = p * p; j <= N; j = j + 2 * p) { setBit(Bit, j); } for (int j = prime[ii - 1] * prime[ii - 1]; j < (prime[ii] * prime[ii]); j++) { if (j > N) { break; } if (checkBit(Bit, j) == 0) { prime[p_pos] = j; // System.out.printf("prime_added %d\n", j) ; p_pos++; } } if (p * p >= N) { break; } } /** / for (int i = 0; i < p_pos; i++) { System.out.printf("%d ", prime[i]); } System.out.printf("Prime count = %d \n", p_pos) ; /**/ return p_pos ; } static void setBit(int[] array, int i) { int j, k; i--; j = i % 30; k = i / 30; // System.out.printf("setBit %d %x %x\n", i+1,array[k], array[k] | digit_2[j] ) ; array[k] = array[k] | digit_2[j]; } static int checkBit(int[] array, int i) { int j, k; i--; j = i % 30; k = i / 30; // System.out.printf("checkBit %d %x %x\n", i+1,array[k], array[k] & digit_2[j] ) ; if ((array[k] & digit_2[j]) == 0) { return 0; } else { return 1; } } ////////////////////////////////////////////////////////// /* 関数 f(b,n) の定義 •n<b のとき f(b,n)=n •n≥b のとき f(b,n)=f(b, floor(n⁄b))+(n mod b) */ static long f(long b, long n) { // System.out.printf("F(%d,%d)\n", b, n) ; /* if (n<b) return n ; else return (f(b, (long) Math.floor(n/b)) + (n % b)) ; */ long ans = 0 ; while (n<=0){ ans = ans + n % b ; n = (long) Math.floor(n/b) ; } return ans ; } }
Main.java:1: error: class, interface, enum, or record expected arc060; ^ Main.java:3: error: class, interface, enum, or record expected import static java.lang.Math.*; ^ Main.java:4: error: class, interface, enum, or record expected import java.util.Arrays; ^ Main.java:5: error: class, interface, enum, or record expected import java.util.Scanner; ^ 4 errors
s333117424
p04016
C++
#include<bits/stdc++.h> using namespace std;long long n,s,sum,g,i,A,B,C;main(){cin>>n>>s;if(n==s){cout<<n+1<<endl;goto F;}for(i=2;i<=min(n+1,3000000LL);i++){sum=0;g=1;while(g<=1LL<<37){sum+=(n/g)%i;g*=i;}if(sum==s){cout<<i<<endl;goto E;}}for(i=min(s,n/1000000);i>=1;i--){A=i,B=s-i;if((n-B)%A!=0)continue;C=(n-B)/A;if(C<=B||C<=1)continue;cout<<C<<endl;goto E;}cout<<"-1"<<endl;E:;}
a.cc:2:49: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 2 | using namespace std;long long n,s,sum,g,i,A,B,C;main(){cin>>n>>s;if(n==s){cout<<n+1<<endl;goto F;}for(i=2;i<=min(n+1,3000000LL);i++){sum=0;g=1;while(g<=1LL<<37){sum+=(n/g)%i;g*=i;}if(sum==s){cout<<i<<endl;goto E;}}for(i=min(s,n/1000000);i>=1;i--){A=i,B=s-i;if((n-B)%A!=0)continue;C=(n-B)/A;if(C<=B||C<=1)continue;cout<<C<<endl;goto E;}cout<<"-1"<<endl;E:;} | ^~~~ a.cc: In function 'int main()': a.cc:2:96: error: label 'F' used but not defined 2 | using namespace std;long long n,s,sum,g,i,A,B,C;main(){cin>>n>>s;if(n==s){cout<<n+1<<endl;goto F;}for(i=2;i<=min(n+1,3000000LL);i++){sum=0;g=1;while(g<=1LL<<37){sum+=(n/g)%i;g*=i;}if(sum==s){cout<<i<<endl;goto E;}}for(i=min(s,n/1000000);i>=1;i--){A=i,B=s-i;if((n-B)%A!=0)continue;C=(n-B)/A;if(C<=B||C<=1)continue;cout<<C<<endl;goto E;}cout<<"-1"<<endl;E:;} | ^
s800038630
p04016
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <map> #include <set> #include <functional> #include <iostream> #define INF 2000000000000LL using namespace std; typedef long long ll; typedef pair<int,int> P; ll n,s; int main(void){ scanf("%lld%lld",&n,&s); if(n==s)printf("%lld\n",n+1LL); for(ll b=2;b*b<=n;b++){ ll c=b,cnt=0,nn=n; while(nn>0){ cnt+=nn%c; nn/=c; } if(cnt==s){ printf("%lld\n",b); return 0; } } ll res=n+1LL; for(ll p=1;p*p<=n;p++){ if(b*p==n-s+p)res=min(res,b); } printf("%lld\n",res==n+1LL?-1:res); return 0; }
a.cc: In function 'int main()': a.cc:35:20: error: 'b' was not declared in this scope 35 | if(b*p==n-s+p)res=min(res,b); | ^
s996674786
p04016
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <map> #include <set> #include <functional> #include <iostream> #define INF 2000000000000LL using namespace std; typedef long long ll; typedef pair<int,int> P; ll n,s; int main(void){ scanf("%lld%lld",&n,&s); ll b; for(b=2;(b-1)*(b-1)<=n;b++){ ll c=b,cnt=0,nn=n; while(nn>0){ cnt+=nn%c; nn/=c; } if(cnt==s){ printf("%lld\n",b); return 0; } } ll sqr=n/b; if(sqr+b-1LL<s)printf("-1\n"); else{ ll res=n+1LL; for(ll i=sqr;i>=1;i--){ ll rest=n-i; for(ll j=max(1,n/(i+1LL));j*j<=min(rest,n/i);j++){ if(rest%j==0){ if(j*(i+1LL)>n && j*i<=n)res=min(res,j); } } } if(res!=n+1LL)printf("%lld\n",res); else printf("-1\n"); } return 0; }
a.cc: In function 'int main()': a.cc:39:37: error: no matching function for call to 'max(int, ll)' 39 | for(ll j=max(1,n/(i+1LL));j*j<=min(rest,n/i);j++){ | ~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/14/vector:62, from a.cc:3: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:39:37: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'}) 39 | for(ll j=max(1,n/(i+1LL));j*j<=min(rest,n/i);j++){ | ~~~^~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61, from a.cc:6: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:39:37: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 39 | for(ll j=max(1,n/(i+1LL));j*j<=min(rest,n/i);j++){ | ~~~^~~~~~~~~~~~~
s442345389
p04016
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <map> #include <set> #include <functional> #include <iostream> #define INF 2000000000000LL using namespace std; typedef long long ll; typedef pair<int,int> P; ll n,s; int main(void){ scanf("%lld%lld",&n,&s); ll b; for(b=2;(b-1)*(b-1)<=n;b++){ ll c=b,cnt=0,nn=n; while(nn>0){ cnt+=nn%c; nn/=c; } if(cnt==s){ printf("%lld\n",b); return 0; } } if(s==1){ printf("%lld\n",n); return 0; } ll sqr=n/b; if(sqr+b-1LL<s)printf("-1\n"); else{ ll res=n+1LL; for(ll i=sqr;i>=1;i--){ ll rest=n-i; for(ll j=max(1,n/(ss+1LL));j*j<=min(rest,n/ss);j++){ if(rest%j==0){ if(j*(i+1LL)>n && j*i<=n)res=min(res,j); if(rest/j*(i+1LL)>n && rest/j*i<=n)res=min(res,rest/j); } } } if(res!=n+1LL)printf("%lld\n",res); else printf("-1\n"); } return 0; }
a.cc: In function 'int main()': a.cc:43:43: error: 'ss' was not declared in this scope; did you mean 's'? 43 | for(ll j=max(1,n/(ss+1LL));j*j<=min(rest,n/ss);j++){ | ^~ | s
s790295083
p04016
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <map> #include <set> #include <functional> #include <iostream> #define INF 2000000000LL using namespace std; typedef long long ll; typedef pair<int,int> P; ll n,s; int main(void){ scanf("%lld%lld",&n,&s); for(ll b=2;(b-1)*(b-1)<=n;b++){ ll c=b,cnt=0,nn=n; while(nn>0){ cnt+=nn%c; nn/=c; } if(cnt==s){ printf("%lld\n",b); return 0; } } if(s==1){ printf("%lld\n",n); return 0; } ll sqr=n/b; if(sqr+b-1LL<s)printf("-1\n"); else printf("%lld\n",n); return 0; }
a.cc: In function 'int main()': a.cc:36:18: error: 'b' was not declared in this scope 36 | ll sqr=n/b; | ^
s893893463
p04016
C++
#include <bits/stdc++.h> using namespace std; namespace { typedef double real; typedef long long ll; template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) { if (vs.empty()) return os << "[]"; os << "[" << vs[0]; for (int i = 1; i < vs.size(); i++) os << " " << vs[i]; return os << "]"; } template<class T> istream& operator>>(istream& is, vector<T>& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } ll N, S; void input() { cin >> N >> S; } bool check(ll b) { ll sum = 0; ll n = N; while (n > 0) { sum += n % b; n /= b; } return sum == S; } void solve() { if (N < S) { cout << -1 << endl; return; } if (N == S) { cout << N + 1 << endl; return; } ll Z = N - S; for (ll x = 2; x * x <= Z; x++) { if (Z % x != 0) continue; // x + 1縺ッb縺ョ蛟呵」・ if (check(x + 1)) { cout << x + 1 << endl; return; } } cout << -1 << endl; } } int main() { input(); solve(); return 0; }
a.cc:55:9: error: 'cout' does not name a type 55 | cout << -1 << endl; | ^~~~ a.cc:58:1: error: expected declaration before '}' token 58 | } | ^
s719782022
p04016
C++
#include<bits/stdc++.h> using namespace std; int main(){ ll n,s,i,j,k,ans=-1; cin>>n>>s; cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:4:3: error: 'll' was not declared in this scope 4 | ll n,s,i,j,k,ans=-1; | ^~ a.cc:5:8: error: 'n' was not declared in this scope; did you mean 'yn'? 5 | cin>>n>>s; | ^ | yn a.cc:5:11: error: 's' was not declared in this scope 5 | cin>>n>>s; | ^ a.cc:6:11: error: 'ans' was not declared in this scope; did you mean 'abs'? 6 | cout << ans << endl; | ^~~ | abs
s232809209
p04016
C++
int main(){ cout<<-1<<endl; return 0; }
a.cc: In function 'int main()': a.cc:2:1: error: 'cout' was not declared in this scope 2 | cout<<-1<<endl; | ^~~~ a.cc:2:11: error: 'endl' was not declared in this scope 2 | cout<<-1<<endl; | ^~~~