buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
#include <iostream>
using namespace std;
int main() {
int d;
while (cin >> d) {
int S = 0;
for (int i = 1; i < 600 / d; i++) {
S += d * d * i * i;
}
cout << S << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
int d;
while (cin >> d) {
int S = 0;
for (int i = 1; i * d < 600; i++) {
S += d * d * d * i * i;
}
cout << S << endl;
}
}
|
[["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 12, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 16, 31, 16, 31, 16, 17, 48]]
| 1
| 62
|
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int f(int x) { return x * x; }
int main() {
int d;
int D = 600;
cin >> d;
int s = 0;
for (int i = 1; i * d < D; i++)
s += f(i * d) * d;
cout << s << endl;
}
|
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int f(int x) { return x * x; }
int main() {
int d;
int D = 600;
while (cin >> d) {
int s = 0;
for (int i = 1; i * d < D; i++)
s += f(i * d) * d;
cout << s << endl;
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 87
|
#include <iostream>
using namespace std;
int main() {
long d;
while (cin >> d) {
long count;
for (int i = 0; i < 600; i += d) {
count += d * i * i;
}
cout << count << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
long d;
while (cin >> d) {
long count = 0;
for (int i = 0; i < 600; i += d) {
count += d * i * i;
}
cout << count << endl;
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13]]
| 1
| 60
|
#include <iostream>
using namespace std;
int main() {
double d;
while (cin >> d) {
double sum = 0;
for (int i = 1; i * d < 600; i++) {
sum = sum + d * (i * d) * (i * d);
}
cout << sum << endl;
}
}
|
#include <iostream>
using namespace std;
int main() {
double d;
while (cin >> d) {
int sum = 0;
for (int i = 0; i * d < 600; i++) {
sum = sum + d * (i * d) * (i * d);
}
cout << sum << endl;
}
}
|
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 70
|
/*#include<stdio.h>
#include <algorithm>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<string>
#include<vector>
#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 CI cin >>
#define CO cout <<
#define E << endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;
string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;
int sum = 0;
vector<int> value;
vector<int> weight;
int dp[110][10010];
int data_[210][2] = { -2 };
void input(void) {
CI n;
return;
}
int main(void) {
input();
double money = 100000;
for (int i = 0; i < n; i++) {
money *= 1.05;
}
if ((int)money % 1000 >= 500) {
CO (int)(money - ((int)(money) % 1000) + 1000) E
}
else {
CO (int)(money - ((int)(money) % 1000)) E
}
return 0;
}
*/
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#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 CI cin >>
#define CO cout <<
#define E << endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
long long int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;
string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;
int sum = 0;
vector<int> value;
vector<int> weight;
int dp[110][10010];
int data_[210][2] = {-2};
void input(void) { return; }
int main(void) {
int i = 1;
int sum = 0;
while (scanf("%d", &n) != EOF) {
while (true) {
sum += (n * n * (i - 1) * n * (i - 1));
if ((n * i) == 600)
break;
i++;
}
CO sum E sum = 0;
i = 0;
}
return 0;
}
|
/*#include<stdio.h>
#include <algorithm>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<string>
#include<vector>
#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 CI cin >>
#define CO cout <<
#define E << endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;
string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;
int sum = 0;
vector<int> value;
vector<int> weight;
int dp[110][10010];
int data_[210][2] = { -2 };
void input(void) {
CI n;
return;
}
int main(void) {
input();
double money = 100000;
for (int i = 0; i < n; i++) {
money *= 1.05;
}
if ((int)money % 1000 >= 500) {
CO (int)(money - ((int)(money) % 1000) + 1000) E
}
else {
CO (int)(money - ((int)(money) % 1000)) E
}
return 0;
}
*/
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#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 CI cin >>
#define CO cout <<
#define E << endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
long long int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;
string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;
int sum = 0;
vector<int> value;
vector<int> weight;
int dp[110][10010];
int data_[210][2] = {-2};
void input(void) { return; }
int main(void) {
int i = 1;
int sum = 0;
while (scanf("%d", &n) != EOF) {
while (true) {
sum += (n * n * (i - 1) * n * (i - 1));
if ((n * i) == 600)
break;
i++;
}
CO sum E sum = 0;
i = 1;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 373
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int d;
cin >> d;
int n = 600 / d;
int ans = 0;
for (int i = 1; i < n; i++) {
ans += d * (i * d * i * d);
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int d;
while (cin >> d) {
int n = 600 / d;
long ans = 0;
for (int i = 1; i < n; i++) {
ans += d * (i * d * i * d);
}
cout << ans << endl;
}
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 52, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
| 1
| 69
|
def f(x)
x * x
end
l = gets.chomp.to_i
a = 600
p = 0
sum = 0
while a > p
sum += l * f(p)
p += l
end
puts sum
|
def f(x)
x * x
end
while l = gets
l = l.chomp.to_i
a = 600
p = 0
sum = 0
while a > p
sum += l * f(p)
p += l
end
puts sum
end
|
[["+", 36, 36, 36, 36, 0, 493, 0, 89, 0, 89], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 31, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 662, 0, 32], ["+", 8, 170, 0, 662, 12, 652, 486, 652, 486, 22], ["+", 36, 36, 0, 493, 0, 89, 8, 170, 0, 444]]
| 4
| 43
|
#!/usr/local/bin/ruby
def f(x)
x * x
end
while line = gets
d = line.to_i
(0..(600 - 2 * d) / d).each do |_i|
a += d
sum += f(a)
end
ans = sum * d
puts ans.to_s
a = 0
ans = 0
sum = 0
end
|
#!/usr/local/bin/ruby
a = 0
sum = 0
def f(x)
x * x
end
while line = gets
d = line.to_i
(0..(600 - 2 * d) / d).each do |_i|
a += d
sum += f(a)
end
ans = sum * d
puts ans.to_s
a = 0
ans = 0
sum = 0
end
|
[["+", 36, 36, 36, 36, 0, 493, 0, 662, 31, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 0, 32], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 12, 612]]
| 4
| 67
|
def square(n)
n * n
end
# main
arr = []
while n = gets
arr << n.to_i
end
p arr
arr.each do |d|
sum = 0
0.upto(600 / d - 1) do |i|
sum += square(i * d) * d
end
puts sum
end
|
def square(n)
n * n
end
# main
arr = []
while n = gets
arr << n.to_i
end
arr.each do |d|
sum = 0
0.upto(600 / d - 1) do |i|
sum += square(i * d) * d
end
puts sum
end
|
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 36, 36, 0, 493, 0, 652, 3, 4, 0, 22]]
| 4
| 64
|
import sys
for d in map(int, sys.stdin):
sum = 0
for x in range(d, 600, d):
sum += (x**2)*d
print(s)
|
import sys
for d in map(int, sys.stdin):
sum = 0
for x in range(d, 600, d):
sum += (x**2)*d
print(sum)
|
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
| 5
| 42
|
import sys
X = 600
for line in sys.stdin:
s=0
d = int(line)
for nowx in range(0,X,d):
s += d*(nowx**2)
print(nowx)
print(s)
|
import sys
X = 600
for line in sys.stdin:
s=0
d = int(line)
for nowx in range(0,X,d):
s += d*(nowx**2)
print(s)
|
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
| 5
| 50
|
import sys
a = []
for line in sys.stdin:
a.append(line)
for n in a:
num=int(n)
x=0
are=0
while x<600:
are+=(x**2)*num
x+=num
print(area)
|
import sys
a = []
for line in sys.stdin:
a.append(line)
for n in a:
num=int(n)
x=0
are=0
while x<600:
are+=(x**2)*num
x+=num
print(are)
|
[["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
| 5
| 57
|
import sys
def f(x):
return x ** 2
def integral(d):
s = f(d) * d
for i in range(600 // d - 1):
s += f(d * (i + 1)) * d
return s
lines = sys.stdin.readlines()
for line in lines:
print(integral(int(line)))
|
import sys
def f(x):
return x ** 2
def integral(d):
s = 0
for i in range(600 // d - 1):
s += f(d * (i + 1)) * d
return s
lines = sys.stdin.readlines()
for line in lines:
print(integral(int(line)))
|
[["-", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["-", 0, 662, 12, 657, 31, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 657, 31, 652, 3, 4, 0, 22], ["-", 0, 662, 12, 657, 31, 652, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 48], ["-", 8, 196, 0, 1, 0, 662, 12, 657, 12, 22], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 12, 612]]
| 5
| 78
|
import sys
for line in sys.stdin:
d = int(line)
S = 0
for x in range(1, 600, d):
S += (x ** 2) * d
print(S)
|
import sys
for line in sys.stdin:
d = int(line)
S = 0
for x in range(0, 600, d):
S += (x ** 2) * d
print(S)
|
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 43
|
def f(x):
return x**2
while True:
try:
d0 = input()
if d0 == '':
break
area = []
d = int(d0)
for i in range(d, 600, d):
print(i)
area.append(d*f(i))
Sumpoyo = sum(area)
print(Sumpoyo)
except EOFError:
break
|
def f(x):
return x**2
while True:
try:
d0 = input()
if d0 == '':
break
area = []
d = int(d0)
for i in range(d, 600, d):
area.append(d*f(i))
Sumpoyo = sum(area)
print(Sumpoyo)
except EOFError:
break
|
[["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 78
|
import sys
for d in int(sys.stdin):
print(sum([d*x*x for x in range(d,600,d)]))
|
import sys
for d in map(int, sys.stdin):
print(sum([d*x*x for x in range(d,600,d)]))
|
[["-", 36, 36, 0, 656, 0, 7, 12, 652, 63, 22], ["+", 36, 36, 0, 656, 0, 7, 12, 652, 63, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 21]]
| 5
| 36
|
(function(input) {
var p = input.replace(/\n$/, '').split('\n');
var N = Number(p.shift());
var count = 0;
while (count++ < N) {
var n1 = p.shift();
var n2 = p.shift();
if (n1.length >= 80 || n2.length >= 80) {
console.log('overflow');
continue;
}
var n = sum(n1, n2);
if (n.length >= 80) {
console.log('overflow');
continue;
}
console.log('%s', n);
}
})(require('fs').readFileSync('/dev/stdin', 'utf8'));
function sum(n1, n2) {
var a, b;
if (n1.length > n2.length) {
a = n1.split('').map(Number).reverse();
b = n2.split('').map(Number).reverse();
} else {
b = n1.split('').map(Number).reverse();
a = n2.split('').map(Number).reverse();
}
for (var i = 0; i < b.length; i++) {
a[i] += b[i];
}
for (var i = 0; i < a.length - 1; i++) {
if (a[i] >= 10) {
var m = Math.floor(a[i] / 10);
a[i] = a[i] % 10;
a[i + 1] += m;
}
}
return a.reverse().join('');
}
|
(function(input) {
var p = input.replace(/\n$/, '').split('\n');
var N = Number(p.shift());
var count = 0;
while (count++ < N) {
var n1 = p.shift();
var n2 = p.shift();
if (n1.length > 80 || n2.length > 80) {
console.log('overflow');
continue;
}
var n = sum(n1, n2);
if (n.length > 80) {
console.log('overflow');
continue;
}
console.log('%s', n);
}
})(require('fs').readFileSync('/dev/stdin', 'utf8'));
function sum(n1, n2) {
var a, b;
if (n1.length > n2.length) {
a = n1.split('').map(Number).reverse();
b = n2.split('').map(Number).reverse();
} else {
b = n1.split('').map(Number).reverse();
a = n2.split('').map(Number).reverse();
}
for (var i = 0; i < b.length; i++) {
a[i] += b[i];
}
for (var i = 0; i < a.length - 1; i++) {
if (a[i] >= 10) {
var m = Math.floor(a[i] / 10);
a[i] = a[i] % 10;
a[i + 1] += m;
}
}
return a.reverse().join('');
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 47], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47], ["-", 8, 556, 0, 57, 15, 23, 0, 16, 17, 20], ["+", 8, 556, 0, 57, 15, 23, 0, 16, 17, 47]]
| 2
| 376
|
import java.io.*;
import java.math.*;
public class Main {
public static void main(String args[]) throws IOException {
String str1, str2;
int i, d = 0;
BigInteger big1, big2, total;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
i = Integer.parseInt(input.readLine());
while (d++ < i) {
str1 = input.readLine();
big1 = new BigInteger(str1);
str2 = input.readLine();
big2 = new BigInteger(str2);
total = big1.add(big2);
if (str1.length() > 80 || str2.length() > 80 ||
total.toString().length() > 80)
System.out.println("overflow");
System.out.println(total);
}
}
}
|
import java.io.*;
import java.math.*;
public class Main {
public static void main(String args[]) throws IOException {
String str1, str2;
int i, d = 0;
BigInteger big1, big2, total;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
i = Integer.parseInt(input.readLine());
while (d++ < i) {
str1 = input.readLine();
big1 = new BigInteger(str1);
str2 = input.readLine();
big2 = new BigInteger(str2);
total = big1.add(big2);
if (str1.length() > 80 || str2.length() > 80 ||
total.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println(total);
}
}
}
}
|
[["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
| 3
| 180
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
BigInteger a = new BigInteger(sc.next());
BigInteger b = new BigInteger(sc.next());
BigInteger c = a.add(b);
if (c.toString().length() >= 80) {
System.out.println("overflow");
} else {
System.out.println(c);
}
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
BigInteger a = new BigInteger(sc.next());
BigInteger b = new BigInteger(sc.next());
BigInteger c = a.add(b);
if (c.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println(c);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 47]]
| 3
| 142
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int dataset = scanner.nextInt();
for (int i = 0; i < dataset; i++) {
BigInteger first = scanner.nextBigInteger();
BigInteger second = scanner.nextBigInteger();
BigInteger ans = first.add(second);
if (ans.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println();
}
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int dataset = scanner.nextInt();
for (int i = 0; i < dataset; i++) {
BigInteger first = scanner.nextBigInteger();
BigInteger second = scanner.nextBigInteger();
BigInteger ans = first.add(second);
if (ans.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println(ans);
}
}
}
}
|
[["+", 75, 196, 0, 1, 0, 492, 3, 4, 0, 22]]
| 3
| 133
|
public class Main {
public void run(java.io.InputStream in, java.io.PrintStream out) {
java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
int n;
String a, b;
char[] ca, cb;
int i, j, d;
n = sc.nextInt();
for (i = 0; i < n; i++) {
a = sc.next();
b = sc.next();
d = a.length() + 1;
if (d < b.length() + 1)
d = b.length() + 1;
ca = new char[d];
cb = new char[d];
for (j = 0; j < a.length(); j++)
ca[j] = (char)(a.charAt(a.length() - j - 1) - '0');
for (j = 0; j < b.length(); j++)
cb[j] = (char)(b.charAt(b.length() - j - 1) - '0');
for (j = 0; j < d; j++) {
ca[j] += cb[j];
if (ca[j] > 9) {
ca[j + 1]++;
ca[j] %= 10;
}
}
if (d > 81 || (d == 81 && ca[d - 1] == 0))
out.println("overflow");
else {
for (j = 0; j < d; j++)
if (j != 0 || ca[d - j - 1] != 0) {
out.print((char)(ca[d - j - 1] + '0'));
}
out.println();
}
}
sc.close();
}
public static void main(String[] args) {
(new Main()).run(System.in, System.out);
}
}
|
public class Main {
public void run(java.io.InputStream in, java.io.PrintStream out) {
java.util.Scanner sc = new java.util.Scanner(in);
int n;
String a, b;
char[] ca, cb;
int i, j, d;
n = sc.nextInt();
for (i = 0; i < n; i++) {
a = sc.next();
b = sc.next();
d = a.length() + 1;
if (d < b.length() + 1)
d = b.length() + 1;
ca = new char[d];
cb = new char[d];
for (j = 0; j < a.length(); j++)
ca[j] = (char)(a.charAt(a.length() - j - 1) - '0');
for (j = 0; j < b.length(); j++)
cb[j] = (char)(b.charAt(b.length() - j - 1) - '0');
for (j = 0; j < d - 1; j++) {
ca[j] += cb[j];
if (ca[j] > 9) {
ca[j + 1]++;
ca[j] %= 10;
}
}
if (d > 81 || (d == 81 && ca[d - 1] != 0))
out.println("overflow");
else {
for (j = 0; j < d; j++)
if (j != 0 || ca[d - j - 1] != 0)
out.print((char)(ca[d - j - 1] + '0'));
out.println();
}
}
sc.close();
}
public static void main(String[] args) {
(new Main()).run(System.in, System.out);
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 499], ["-", 0, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["-", 75, 196, 0, 7, 8, 57, 64, 196, 0, 45], ["-", 75, 196, 0, 7, 8, 57, 64, 196, 0, 46]]
| 3
| 419
|
import java.math.BigDecimal;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static long res = 0;
public static void main(String[] args) throws Exception {
int n = sc.nextInt();
while (sc.hasNext()) {
BigDecimal a = new BigDecimal(sc.next());
BigDecimal b = new BigDecimal(sc.next());
a = a.add(b);
String s = a.toPlainString();
if (s.length() >= 80) {
System.out.println("overflow");
} else {
System.out.println(s);
}
}
}
}
|
import java.math.BigDecimal;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static Scanner sc = new Scanner(System.in);
public static long res = 0;
public static void main(String[] args) throws Exception {
int n = sc.nextInt();
while (sc.hasNext()) {
BigDecimal a = new BigDecimal(sc.next());
BigDecimal b = new BigDecimal(sc.next());
a = a.add(b);
String s = a.toPlainString();
if (s.length() > 80) {
System.out.println("overflow");
} else {
System.out.println(s);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 47]]
| 3
| 158
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
String a = sc.next();
String b = sc.next();
int result;
String answer = "";
int m = 0;
if (a.length() > 80 || b.length() > 80) {
System.out.println("overflow");
} else {
for (int i = a.length() - 1, j = b.length() - 1; i >= 0 || j >= 0;
i--, j--) {
result = (i < 0 ? '0' : a.charAt(i)) - '0' +
(j < 0 ? '0' : b.charAt(j)) - '0' + m;
answer += result % 10;
m = result / 10;
}
answer += m == 1 ? m : "";
}
if (answer.length() <= 80)
System.out.println(new StringBuffer(answer).reverse());
else
System.out.println("overflow");
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
String a = sc.next();
String b = sc.next();
int result;
String answer = "";
int m = 0;
if (a.length() > 80 || b.length() > 80) {
System.out.println("overflow");
continue;
} else {
for (int i = a.length() - 1, j = b.length() - 1; i >= 0 || j >= 0;
i--, j--) {
result = (i < 0 ? '0' : a.charAt(i)) - '0' +
(j < 0 ? '0' : b.charAt(j)) - '0' + m;
answer += result % 10;
m = result / 10;
}
answer += m == 1 ? m : "";
}
if (answer.length() <= 80)
System.out.println(new StringBuffer(answer).reverse());
else
System.out.println("overflow");
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35]]
| 3
| 257
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
for (int i = 0; i < N; i++) {
String a = scanner.next(), b = scanner.next();
BigInteger sum = new BigInteger(a), A = new BigInteger(b);
sum.add(A);
if ((sum.toString()).length() > 80) {
System.out.println("overflow");
} else {
System.out.println(sum.toString());
}
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
for (int i = 0; i < N; i++) {
String a = scanner.next(), b = scanner.next();
BigInteger A = new BigInteger(a), B = new BigInteger(b);
BigInteger sum = A.add(B);
if ((sum.toString()).length() > 80) {
System.out.println("overflow");
} else {
System.out.println(sum.toString());
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 7, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 503, 39, 78], ["+", 0, 7, 8, 196, 0, 503, 49, 200, 0, 32], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 500, 22], ["-", 8, 196, 0, 1, 0, 492, 3, 4, 0, 22], ["+", 0, 503, 49, 200, 51, 492, 3, 4, 0, 22]]
| 3
| 153
|
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int times = stdin.nextInt();
for (int i = 0; i < times; i++) {
BigInteger a = new BigInteger(stdin.next());
BigInteger b = new BigInteger(stdin.next()).add(a);
if (b.compareTo(BigInteger.TEN.pow(79)) >= 0) {
System.out.println("overflow");
} else {
System.out.println(b);
}
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int times = stdin.nextInt();
for (int i = 0; i < times; i++) {
BigInteger a = new BigInteger(stdin.next());
BigInteger b = new BigInteger(stdin.next()).add(a);
if (b.compareTo(BigInteger.TEN.pow(80)) >= 0) {
System.out.println("overflow");
} else {
System.out.println(b);
}
}
}
}
|
[["-", 31, 492, 3, 4, 0, 492, 3, 4, 0, 499], ["+", 31, 492, 3, 4, 0, 492, 3, 4, 0, 499]]
| 3
| 140
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int i = 0; i < N; ++i) {
BigInteger n = sc.nextBigInteger();
BigInteger m = sc.nextBigInteger();
BigInteger MAX = new BigInteger(
"10000000000000000000000000000000000000000000000000000000000000000000000000000000");
if (n.add(m).compareTo(MAX) < 0) {
System.out.println(n.add(m));
} else {
System.out.println("overflow");
}
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
for (int i = 0; i < N; ++i) {
BigInteger n = sc.nextBigInteger();
BigInteger m = sc.nextBigInteger();
BigInteger MAX = new BigInteger(
"100000000000000000000000000000000000000000000000000000000000000000000000000000000");
if (n.add(m).compareTo(MAX) < 0) {
System.out.println(n.add(m));
} else {
System.out.println("overflow");
}
}
}
}
|
[["-", 49, 200, 51, 230, 3, 4, 0, 5, 0, 491], ["+", 49, 200, 51, 230, 3, 4, 0, 5, 0, 491]]
| 3
| 142
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args)
throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BigInteger a, b;
final BigInteger max = new BigInteger(
"10000000000000000000000000000000000000000000000000000000000000000000000000000000");
final BigInteger one = new BigInteger("1");
final int loop;
loop = Integer.parseInt(br.readLine());
for (int i = 0; i < loop; i++) {
a = new BigInteger(br.readLine());
b = new BigInteger(br.readLine());
if (a.divide(max).compareTo(one) >= 0 ||
a.divide(max).compareTo(one) >= 0) {
System.out.println("overflow");
continue;
}
BigInteger sum = a.add(b);
if (sum.divide(max).compareTo(one) >= 0) {
System.out.println("overflow");
continue;
}
System.out.println(sum);
}
}
}
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args)
throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BigInteger a, b;
final BigInteger max = new BigInteger(
"100000000000000000000000000000000000000000000000000000000000000000000000000000000");
final BigInteger one = new BigInteger("1");
final int loop;
loop = Integer.parseInt(br.readLine());
for (int i = 0; i < loop; i++) {
a = new BigInteger(br.readLine());
b = new BigInteger(br.readLine());
if (a.divide(max).compareTo(one) >= 0 ||
a.divide(max).compareTo(one) >= 0) {
System.out.println("overflow");
continue;
}
BigInteger sum = a.add(b);
if (sum.divide(max).compareTo(one) >= 0) {
System.out.println("overflow");
continue;
}
System.out.println(sum);
}
}
}
|
[["-", 49, 200, 51, 230, 3, 4, 0, 5, 0, 491], ["+", 49, 200, 51, 230, 3, 4, 0, 5, 0, 491]]
| 3
| 245
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String numstr = "";
for (int i = 0; i < 79; i++) {
numstr += "9";
}
int n;
BigInteger a, b, c;
BigInteger max = new BigInteger(numstr); // numstr : 9999 ... 999
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 0; i < n; i++) {
a = sc.nextBigInteger();
b = sc.nextBigInteger();
c = a.add(b);
if (c.compareTo(max) > 0) {
System.out.println("overflow");
} else {
System.out.println(c.toString());
}
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String numstr = "";
for (int i = 0; i < 80; i++) {
numstr += "9";
}
int n;
BigInteger a, b, c;
BigInteger max = new BigInteger(numstr); // numstr : 9999 ... 999
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 0; i < n; i++) {
a = sc.nextBigInteger();
b = sc.nextBigInteger();
c = a.add(b);
if (c.compareTo(max) > 0) {
System.out.println("overflow");
} else {
System.out.println(c.toString());
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 499], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 499]]
| 3
| 179
|
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int dataSet = scan.nextInt();
BigDecimal[] ans = new BigDecimal[dataSet];
for (int i = 0; i < dataSet; i++) {
ans[i] = scan.nextBigDecimal().add(scan.nextBigDecimal());
}
for (int i = 0; i < dataSet; i++) {
if (String.valueOf(ans[i]).toCharArray().length >= 80) {
System.out.println("overflow");
} else {
System.out.println(ans[i]);
}
}
}
}
|
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// scan.useDelimiter("\\r\\n");
int dataSet = scan.nextInt();
BigDecimal[] ans = new BigDecimal[dataSet];
for (int i = 0; i < dataSet; i++) {
ans[i] = scan.nextBigDecimal().add(scan.nextBigDecimal());
}
for (int i = 0; i < dataSet; i++) {
if (String.valueOf(ans[i]).toCharArray().length > 80) {
System.out.println("overflow");
} else {
System.out.println(ans[i]);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 47]]
| 3
| 162
|
import java.util.*;
public class Main {
public void doIt() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
String str1 = new StringBuilder(sc.next()).reverse().toString();
String str2 = new StringBuilder(sc.next()).reverse().toString();
int maxlen = Math.max(str1.length(), str2.length());
if (maxlen > 80) {
System.out.println("overflow");
return;
}
int[] ans = new int[maxlen + 1];
int len = str1.length();
for (int i = 0; i < len; i++) {
ans[i] = str1.charAt(i) - '0';
}
len = str2.length();
for (int i = 0; i < len; i++) {
ans[i] += str2.charAt(i) - '0';
}
len = ans.length - 1;
for (int i = 0; i < len; i++) {
if (ans[i] >= 10) {
ans[i + 1]++;
ans[i] = ans[i] - 10;
}
}
if (ans.length == 81 && ans[80] == 1) {
System.out.println("overflow");
} else {
if (ans[len] == 1) {
System.out.print(1);
}
for (int i = ans.length - 2; i >= 0; i--) {
System.out.print(ans[i]);
}
System.out.println("");
}
}
}
public static void main(String[] args) {
Main obj = new Main();
obj.doIt();
}
}
|
import java.util.*;
public class Main {
public void doIt() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
String str1 = new StringBuilder(sc.next()).reverse().toString();
String str2 = new StringBuilder(sc.next()).reverse().toString();
int maxlen = Math.max(str1.length(), str2.length());
if (maxlen > 80) {
System.out.println("overflow");
continue;
}
int[] ans = new int[maxlen + 1];
int len = str1.length();
for (int i = 0; i < len; i++) {
ans[i] = str1.charAt(i) - '0';
}
len = str2.length();
for (int i = 0; i < len; i++) {
ans[i] += str2.charAt(i) - '0';
}
len = ans.length - 1;
for (int i = 0; i < len; i++) {
if (ans[i] >= 10) {
ans[i + 1]++;
ans[i] = ans[i] - 10;
}
}
if (ans.length == 81 && ans[80] != 0) {
System.out.println("overflow");
} else {
if (ans[len] == 1) {
System.out.print(1);
}
for (int i = ans.length - 2; i >= 0; i--) {
System.out.print(ans[i]);
}
System.out.println("");
}
}
}
public static void main(String[] args) {
Main obj = new Main();
obj.doIt();
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 0, 57, 15, 15, 0, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 15, 0, 16, 12, 16, 12, 499], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 12, 499]]
| 3
| 395
|
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
while (n != 0) {
BigInteger bi1 = new BigInteger(scan.next());
BigInteger bi2 = new BigInteger(scan.next());
BigInteger ans = bi1.add(bi2);
if (ans.toString().length() < 80)
System.out.println(ans);
else
System.out.println("overflow");
n--;
}
}
}
|
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws java.io.IOException {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
while (n != 0) {
BigInteger bi1 = new BigInteger(scan.next());
BigInteger bi2 = new BigInteger(scan.next());
BigInteger ans = bi1.add(bi2);
if (ans.toString().length() <= 80)
System.out.println(ans);
else
System.out.println("overflow");
n--;
}
}
}
|
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 19]]
| 3
| 139
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n = stdIn.nextInt();
for (int i = 0; i < n; i++) {
String inputBigInt1 = stdIn.next();
String inputBigInt2 = stdIn.next();
if (inputBigInt1.length() >= 80 | inputBigInt2.length() >= 80) {
System.out.println("overflow");
continue;
}
BigInteger bigInt1 = new BigInteger(inputBigInt1);
BigInteger bigInt2 = new BigInteger(inputBigInt2);
BigInteger sumBigInt = bigInt1.add(bigInt2);
if (sumBigInt.toString().length() >= 80) {
System.out.println("overflow");
continue;
}
System.out.println(sumBigInt);
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n = stdIn.nextInt();
for (int i = 0; i < n; i++) {
String inputBigInt1 = stdIn.next();
String inputBigInt2 = stdIn.next();
if (inputBigInt1.length() > 80 | inputBigInt2.length() > 80) {
System.out.println("overflow");
continue;
}
BigInteger bigInt1 = new BigInteger(inputBigInt1);
BigInteger bigInt2 = new BigInteger(inputBigInt2);
BigInteger sumBigInt = bigInt1.add(bigInt2);
if (sumBigInt.toString().length() > 80) {
System.out.println("overflow");
continue;
}
System.out.println(sumBigInt);
}
}
}
|
[["-", 0, 57, 15, 15, 0, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 15, 0, 16, 31, 16, 17, 47], ["-", 0, 57, 15, 15, 0, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 47]]
| 3
| 184
|
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger a, b, c;
String s, ss, sss;
int n = cin.nextInt();
while (n-- != 0) {
a = cin.nextBigInteger();
b = cin.nextBigInteger();
s = a.toString();
ss = b.toString();
if (s.length() > 80 || ss.length() > 80) {
System.out.println("Overflow");
continue;
} else {
c = a.add(b);
sss = c.toString();
if (sss.length() > 80) {
System.out.println("Overflow");
continue;
} else
System.out.println(c);
}
}
}
}
|
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger a, b, c;
String s, ss, sss;
int n = cin.nextInt();
while (n-- != 0) {
a = cin.nextBigInteger();
b = cin.nextBigInteger();
s = a.toString();
ss = b.toString();
if (s.length() > 80 || ss.length() > 80) {
System.out.println("overflow");
continue;
} else {
c = a.add(b);
sss = c.toString();
if (sss.length() > 80) {
System.out.println("overflow");
continue;
} else
System.out.println(c);
}
}
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
| 3
| 194
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
StringBuffer int1 = new StringBuffer(scanner.next());
StringBuffer int2 = new StringBuffer(scanner.next());
StringBuffer result = new StringBuffer();
int carry = 0;
int1.reverse();
int2.reverse();
int maxDig = Math.max(int1.length(), int2.length());
if (maxDig > 80) {
System.out.println("overflow");
break;
}
for (int k = 0; k < maxDig; k++) {
int aInt1 = 0;
int aInt2 = 0;
if (k < int1.length()) {
aInt1 = Integer.parseInt(int1.substring(k, k + 1));
}
if (k < int2.length()) {
aInt2 = Integer.parseInt(int2.substring(k, k + 1));
}
int aSum = carry + aInt1 + aInt2;
if (aSum >= 10) {
carry = 1;
result.append(aSum - 10);
} else {
carry = 0;
result.append(aSum);
}
}
if (carry == 1) {
result.append(1);
}
if (result.length() > 80) {
System.out.println("overflow");
}
System.out.println(result.reverse());
}
}
}
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
StringBuffer int1 = new StringBuffer(scanner.next());
StringBuffer int2 = new StringBuffer(scanner.next());
StringBuffer result = new StringBuffer();
int carry = 0;
int1.reverse();
int2.reverse();
int maxDig = Math.max(int1.length(), int2.length());
if (maxDig > 80) {
System.out.println("overflow");
continue;
}
for (int k = 0; k < maxDig; k++) {
int aInt1 = 0;
int aInt2 = 0;
if (k < int1.length()) {
aInt1 = Integer.parseInt(int1.substring(k, k + 1));
}
if (k < int2.length()) {
aInt2 = Integer.parseInt(int2.substring(k, k + 1));
}
int aSum = carry + aInt1 + aInt2;
if (aSum >= 10) {
carry = 1;
result.append(aSum - 10);
} else {
carry = 0;
result.append(aSum);
}
}
if (carry == 1) {
result.append(1);
}
if (result.length() > 80) {
System.out.println("overflow");
} else {
System.out.println(result.reverse());
}
}
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 3
| 333
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
BigInteger a = sc.nextBigInteger();
BigInteger b = sc.nextBigInteger();
a.add(b);
System.out.println(80 < a.toString().length() ? "overflow"
: a.toString());
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
BigInteger a = sc.nextBigInteger();
BigInteger b = sc.nextBigInteger();
BigInteger ans = a.add(b);
System.out.println(80 < ans.toString().length() ? "overflow"
: ans.toString());
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 503, 39, 78], ["+", 0, 7, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 7, 8, 196, 0, 503, 49, 200, 0, 32], ["-", 0, 510, 15, 16, 12, 492, 500, 492, 500, 22], ["+", 0, 510, 15, 16, 12, 492, 500, 492, 500, 22], ["-", 0, 492, 3, 4, 0, 510, 75, 492, 500, 22], ["+", 0, 492, 3, 4, 0, 510, 75, 492, 500, 22]]
| 3
| 121
|
import java.math.*;
import java.util.*;
public class Main {
public static void main(String args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for (int i = 0; i < n; i++) {
BigInteger a = s.nextBigInteger();
BigInteger b = s.nextBigInteger();
BigInteger c = a.add(b);
if (c.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println(c);
}
}
}
}
|
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for (int i = 0; i < n; i++) {
BigInteger a = s.nextBigInteger();
BigInteger b = s.nextBigInteger();
BigInteger c = a.add(b);
if (c.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println(c);
}
}
}
}
|
[["+", 54, 495, 0, 496, 39, 224, 497, 497, 0, 70], ["+", 54, 495, 0, 496, 39, 224, 497, 497, 0, 73]]
| 3
| 132
|
import java.io.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(in.readLine());
BigInteger a, b;
for (int i = 0; i < N; i++) {
a = new BigInteger(in.readLine());
b = new BigInteger(in.readLine());
if (a.toString().length() > 80 || b.toString().length() > 80) {
System.out.println("overflow");
break;
}
a = a.add(b);
if (a.toString().length() > 80)
System.out.println("overflow");
else {
System.out.println(a.toString());
}
}
}
}
|
import java.io.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(in.readLine());
BigInteger a, b;
for (int i = 0; i < N; i++) {
a = new BigInteger(in.readLine());
b = new BigInteger(in.readLine());
if (a.toString().length() > 80 || b.toString().length() > 80) {
System.out.println("overflow");
continue;
}
a = a.add(b);
if (a.toString().length() > 80)
System.out.println("overflow");
else {
System.out.println(a.toString());
}
}
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117]]
| 3
| 198
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
String a = br.readLine();
String b = br.readLine();
if (a.length() > 80 || b.length() > 80) {
System.out.println("overflow");
}
BigInteger A = new BigInteger(a);
BigInteger B = new BigInteger(b);
BigInteger C = A.add(B);
if (C.toString().length() > 80) {
System.out.println("overflow");
}
System.out.println(C);
}
if (br != null) {
br.close();
br = null;
}
}
}
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
String a = br.readLine();
String b = br.readLine();
if (a.length() > 80 || b.length() > 80) {
System.out.println("overflow");
continue;
}
BigInteger A = new BigInteger(a);
BigInteger B = new BigInteger(b);
BigInteger C = A.add(B);
if (C.toString().length() > 80) {
System.out.println("overflow");
continue;
}
System.out.println(C);
}
if (br != null) {
br.close();
br = null;
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 3
| 216
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int temp = Integer.valueOf(scan.nextLine());
for (int i = 0; i < temp; i++) {
BigInteger a1 = new BigInteger(scan.nextLine());
BigInteger a2 = new BigInteger(scan.nextLine());
a1 = a1.add(a2);
if (a1.toString().length() > 80) {
System.out.println("overflow");
}
System.out.println(a1);
}
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int temp = Integer.valueOf(scan.nextLine());
for (int i = 0; i < temp; i++) {
BigInteger a1 = new BigInteger(scan.nextLine());
BigInteger a2 = new BigInteger(scan.nextLine());
a1 = a1.add(a2);
if (a1.toString().length() > 80) {
System.out.println("overflow");
} else {
System.out.println(a1);
}
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 3
| 143
|
require 'English'
MAX = 1000
prime = Array.new(1_000_001, true)
prime[0] = false
prime[1] = false
(2..MAX).each do |i|
j = i * i
while j < 1_000_000
prime[j] = false
j += i
end
end
while gets
n = $LAST_READ_LINE.to_i
ans = 0
n.times do |i|
ans += 1 if prime[i]
end
puts ans
end
|
require 'English'
MAX = 1000
prime = Array.new(1_000_001, true)
prime[0] = false
prime[1] = false
(2..MAX).each do |i|
j = i * i
while j < 1_000_000
prime[j] = false
j += i
end
end
while gets
n = $LAST_READ_LINE.to_i
ans = 0
(2..n).each do |i|
ans += 1 if prime[i]
end
puts ans
end
|
[["+", 0, 89, 8, 170, 0, 652, 486, 739, 0, 24], ["+", 8, 170, 0, 652, 486, 739, 0, 475, 756, 612], ["+", 8, 170, 0, 652, 486, 739, 0, 475, 17, 757], ["+", 0, 89, 8, 170, 0, 652, 486, 739, 0, 25], ["-", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22], ["+", 0, 493, 0, 89, 8, 170, 0, 652, 735, 22]]
| 4
| 89
|
require 'prime'
primes = Prime.each(999_999).to_a
while (l = gets)
puts primes.count { |p| p < l.to_i }
end
|
require 'prime'
primes = Prime.each(999_999).to_a
while (l = gets)
puts primes.count { |p| p <= l.to_i }
end
|
[["-", 0, 652, 196, 196, 8, 734, 0, 738, 17, 18], ["+", 0, 652, 196, 196, 8, 734, 0, 738, 17, 19]]
| 4
| 35
|
require 'Prime'
while s = gets
puts Prime.each(s.to_i).count
end
|
require 'prime'
while s = gets
puts Prime.each(s.to_i).count
end
|
[["-", 0, 493, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 493, 0, 652, 3, 4, 0, 557, 0, 6]]
| 4
| 20
|
$stdin.read.split("\n").map { |i| i.chomp.to_i }.each do |max|
table = Array.new(max + 1, true)
prime_list = []
(2..max).each do |num|
prime_list << num if table[num] == true
k = num * num
while k <= max
table[k] = false
k += num
end
end
prime_list.count
end
|
$stdin.read.split("\n").map { |i| i.chomp.to_i }.each do |max|
table = Array.new(max + 1, true)
prime_list = []
(2..max).each do |num|
prime_list << num if table[num] == true
k = num * num
while k <= max
table[k] = false
k += num
end
end
puts prime_list.count
end
|
[["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
| 4
| 89
|
require 'English'
def get_prime_list(n)
sn = (n**0.5).to_i
is_prime = [false, false] + [true] * (n - 1)
(2..sn).each do |i|
next unless is_prime[i]
(i * i).step(n, i) do |j|
is_prime[j] = false
end
end
(2..n).to_a.select { |i| is_prime[i] }
end
list = get_prime_list(999_999)
while gets
max = $LAST_READ_LINE.to_i
puts list.select { |nu| nu < max }.count
end
|
require 'English'
def get_prime_list(n)
sn = (n**0.5).to_i
is_prime = [false, false] + [true] * (n - 1)
(2..sn).each do |i|
next unless is_prime[i]
(i * i).step(n, i) do |j|
is_prime[j] = false
end
end
(2..n).to_a.select { |i| is_prime[i] }
end
list = get_prime_list(999_999)
while gets
max = $LAST_READ_LINE.to_i
puts list.select { |nu| nu <= max }.count
end
|
[["-", 486, 652, 196, 196, 8, 734, 0, 738, 17, 18], ["+", 486, 652, 196, 196, 8, 734, 0, 738, 17, 19]]
| 4
| 123
|
require 'prime'
gets.split.map(&:to_i).each do |i|
puts Prime.each(i).to_a.size
end
|
require 'prime'
while l = gets
l.split.map(&:to_i).each do |i|
puts Prime.each(i).to_a.size
end
end
|
[["+", 36, 36, 36, 36, 0, 493, 0, 89, 0, 89], ["+", 36, 36, 0, 493, 0, 89, 15, 662, 31, 22], ["+", 36, 36, 0, 493, 0, 89, 15, 662, 0, 32], ["+", 8, 170, 0, 652, 486, 652, 486, 652, 486, 22], ["+", 0, 89, 8, 170, 0, 652, 196, 737, 0, 444]]
| 4
| 31
|
require 'prime'
$primes = []
def main
$primes = Prime.first 80_000
while num = gets
num = num.chomp.to_i
puts solve(num).to_s
end
end
def solve(num)
nn = $primes.bsearch { |x| x >= num }
$primes.index nn
end
main
|
require 'prime'
$primes = []
def main
$primes = Prime.first 80_000
while num = gets
num = num.chomp.to_i
puts solve(num).to_s
end
end
def solve(num)
nn = $primes.bsearch { |x| x > num }
$primes.index nn
end
main
|
[["-", 12, 652, 196, 196, 8, 734, 0, 738, 17, 20], ["+", 12, 652, 196, 196, 8, 734, 0, 738, 17, 47]]
| 4
| 60
|
prime=[2]
for i in range(3,100,2):
primeq=True
for p in prime:
if i%p==0:
primeq=False
break
if i<p*p:break
if primeq:prime.append(i)
while True:
try:
n=int(input())
ans=0
for p in prime:
if p>n:break
ans+=1
print(ans)
except:break
|
prime=[2]
for i in range(3,1000000,2):
primeq=True
for p in prime:
if i%p==0:
primeq=False
break
if i<p*p:break
if primeq:prime.append(i)
while True:
try:
n=int(input())
ans=0
for p in prime:
if p>n:break
ans+=1
print(ans)
except:break
|
[["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612]]
| 5
| 90
|
# AOJ 0009
import sys
ps = [0]*10**6
used = [False]*10**6
p = 0
def sieve():
global p
used[0] = used[1] = True
for i in range(0,10**6):
if not used[i]:
ps[p] = i
p+=1
for j in range(i,10**6,i):
used[j] = True
def upper_bound(x):
lb = 0
ub = p
while ub-lb > 1:
mid = lb+ub>>1
if ps[mid] <= x:
lb = mid
else:
ub = mid
return ub
sieve()
for i in sys.stdin:
print(upper_bound(int(i)))
|
# AOJ 0009
import sys
ps = [0]*10**6
used = [False]*10**6
p = 0
def sieve():
global p
used[0] = used[1] = True
for i in range(0,10**6):
if not used[i]:
ps[p] = i
p+=1
for j in range(i,10**6,i):
used[j] = True
def upper_bound(x):
lb = -1
ub = p
while ub-lb > 1:
mid = lb+ub>>1
if ps[mid] > x:
ub = mid
else:
lb = mid
return ub
sieve()
for i in sys.stdin:
print(upper_bound(int(i)))
|
[["-", 0, 14, 8, 196, 0, 1, 0, 662, 12, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 664, 17, 33], ["+", 8, 196, 0, 1, 0, 662, 12, 664, 28, 612], ["-", 0, 52, 8, 196, 0, 57, 15, 666, 667, 19], ["+", 0, 52, 8, 196, 0, 57, 15, 666, 667, 47], ["-", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["-", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22]]
| 5
| 154
|
import sys
n_list = list(map(int, sys.stdin.readlines()))
n_max = max(n_list)
pn_candidates = [0] + [1] * (n_max - 1)
pn = 2
while pn < n_max:
if pn_candidates[pn - 1] != 1:
pn += 1
continue
i = 2
while pn * i < n_max:
pn_candidates[pn * i - 1] = 0
i += 1
pn += 1
for n in n_list:
print(sum(pn_candidates[:n]))
|
import sys
n_list = list(map(int, sys.stdin.readlines()))
n_max = max(n_list)
pn_candidates = [0] + [1] * (n_max - 1)
pn = 2
while pn <= n_max:
if pn_candidates[pn - 1] != 1:
pn += 1
continue
i = 2
while pn * i <= n_max:
pn_candidates[pn * i - 1] = 0
i += 1
pn += 1
for n in n_list:
print(sum(pn_candidates[:n]))
|
[["-", 36, 36, 0, 656, 0, 52, 15, 666, 667, 18], ["+", 36, 36, 0, 656, 0, 52, 15, 666, 667, 19], ["-", 0, 52, 8, 196, 0, 52, 15, 666, 667, 18], ["+", 0, 52, 8, 196, 0, 52, 15, 666, 667, 19]]
| 5
| 104
|
n = []
while True:
try:n.append(int(input()))
except:break
R = max(n)+1
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
if p[i]:
p[2*i::i] = [0]*len(p[2*i::i])
print(p)
for i in n:
print(sum(p[:i+1]))
|
n = []
while True:
try:n.append(int(input()))
except:break
R = max(n)+1
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
if p[i]:
p[2*i::i] = [0]*len(p[2*i::i])
for i in n:
print(sum(p[:i+1]))
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 144
|
import math
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
for i in n:
print(sum(p[:i]))
|
import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
for j in range(2*i+1,r,i+1):
p[j] = 0
for i in n:
print(sum(p[:i]))
|
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 70], ["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 73]]
| 5
| 109
|
import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
p[2*i+1::i+1] = [0]*list(range(2*i+1,r,i+1))
for i in n:
print(sum(p[:i]))
|
import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
for i in n:
print(sum(p[:i]))
|
[["-", 0, 1, 0, 662, 12, 657, 31, 634, 0, 73], ["-", 64, 196, 0, 1, 0, 662, 12, 657, 17, 48], ["-", 0, 1, 0, 662, 12, 657, 12, 652, 63, 22], ["-", 0, 662, 12, 657, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 0, 88], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 31, 22], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 0, 267], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 662, 12, 658, 0, 73]]
| 5
| 124
|
import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
p[1::2] = [0 for x in range(0,r,2)]
for i in range(2,sqrt,2):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
for i in n:
print(sum(p[:i]))
|
import math
n = []
while True:
try:
n.append(int(input()))
except:
break
r = max(n)+1
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
p[3::2] = [0 for x in range(3,r,2)]
for i in range(2,sqrt,2):
if p[i]:
p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
for i in n:
print(sum(p[:i]))
|
[["-", 0, 1, 0, 662, 31, 206, 206, 663, 0, 612], ["+", 0, 1, 0, 662, 31, 206, 206, 663, 0, 612], ["-", 12, 658, 0, 659, 12, 652, 3, 4, 0, 612], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 612]]
| 5
| 147
|
# -*- coding;utf-8 -*-
def sieve(n):
p = 0
primes = []
is_prime = [True]*(n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n+1):
if(is_prime[i]):
primes.append(i)
p += 1
for j in range(i*2,n,i):#iごとに増える
is_prime[j] = False
return p
if(__name__ == "__main__"):
while(True):
try:
n = int(input())
except:
break
print(sieve(n))
|
# -*- coding;utf-8 -*-
def sieve(n):
p = 0
primes = []
is_prime = [True]*(n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, n+1):
if(is_prime[i]):
primes.append(i)
p += 1
for j in range(i*2,n+1,i):#iごとに増える
is_prime[j] = False
return p
if(__name__ == "__main__"):
while(True):
try:
n = int(input())
except:
break
print(sieve(n))
|
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 123
|
while True:
try:
n=int(input())
a=[True]*(n+1)
a[0]=a[1]=False
for i in range(2,int(n**0.5)+1):
if a[i]:
for j in range(i**2,n,i):
a[j]=False
print(a.count(True))
except:
break
|
while True:
try:
n=int(input())
a=[True]*(n+1)
a[0]=a[1]=False
for i in range(2,int(n**0.5)+1):
if a[i]:
for j in range(i**2,n+1,i):
a[j]=False
print(a.count(True))
except:
break
|
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 90
|
import sys
n=999999
prime = [1]*(n+1)
(prime[0],prime[1])=(0,0)
for i in [v for v in range(2,n+1) if v*v<n+1]:
for j in range(i*i,n+1,i):
prime[j]=0
for inp in sys.stdin:
print(prime[:int(inp)-1].count(1))
|
import sys
n=999999
prime = [1]*(n+1)
(prime[0],prime[1])=(0,0)
for i in [v for v in range(2,n+1) if v*v<n+1]:
for j in range(i*i,n+1,i):
prime[j]=0
for inp in sys.stdin:
print(prime[:int(inp)+1].count(1))
|
[["-", 63, 319, 500, 206, 206, 663, 0, 657, 17, 33], ["+", 63, 319, 500, 206, 206, 663, 0, 657, 17, 72]]
| 5
| 106
|
import sys
ary=[]
for i in sys.stdin:
ary.append(int(i))
m = max(ary)
prime=[1] * (m + 1)
prime[0] = prime[1] = 0
for i in range(2, int(m ** 0.5) + 1):
if prime[i] == 1:
for j in range(i*2, m + 1, i):
prime[j] = 0
for i in range(len(ary)):
print(sum(prime[:ary[i]]))
|
import sys
ary=[]
for i in sys.stdin:
ary.append(int(i))
m = max(ary)
prime=[1] * (m + 1)
prime[0] = prime[1] = 0
for i in range(2, int(m ** 0.5) + 1):
if prime[i] == 1:
for j in range(i*2, m + 1, i):
prime[j] = 0
for i in range(len(ary)):
print(sum(prime[:ary[i] + 1]))
|
[["+", 3, 4, 0, 206, 206, 663, 0, 657, 17, 72], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612]]
| 5
| 122
|
prime=[False]*1000000
for i in range(2,1001):
for j in range(i*2,1000000,i):
prime[j]=True
while True:
try:
n=int(input())
except:
break
print(prime[:n+1].count(False))
|
prime=[False]*1000000
for i in range(2,1001):
for j in range(i*2,1000000,i):
prime[j]=True
while True:
try:
n=int(input())
except:
break
print(prime[2:n+1].count(False))
|
[["+", 0, 652, 63, 319, 500, 206, 206, 663, 0, 612]]
| 5
| 68
|
import sys
import math
N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])
for i in range(3,int(math.sqrt(N)),2):
if primes[i]:
primes[i*i::i*2] = [0] * len(primes[i*i::i*2])
for i in sys.stdin:
n = int(i)
print(sum(primes[0:n]))
|
import sys
import math
N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])
for i in range(3,int(math.sqrt(N)),2):
if primes[i]:
primes[i*i::i*2] = [0] * len(primes[i*i::i*2])
for i in sys.stdin:
n = int(i)
print(sum(primes[0:n+1]))
|
[["+", 3, 4, 0, 206, 206, 663, 0, 657, 17, 72], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612]]
| 5
| 129
|
import sys
x = 500000
f = [0, 1] * xx
i = 3
while i * i <= 2 * xx:
if f[i] == 1:
j = i * i
while j <= 2 * xx:
f[j] = 0
j += i + i
i += 2
f.pop(0)
f.pop(1)
for n in sys.stdin:
i = int(n)
if i < 2:
print(0)
else:
print(sum(f[:i - 1]))
|
import sys
xx = 500000
f = [0, 1] * xx
i = 3
while i * i <= 2 * xx:
if f[i] == 1:
j = i * i
while j <= 2 * xx:
f[j] = 0
j += i + i
i += 2
f.pop(0)
f.pop(1)
for n in sys.stdin:
i = int(n)
if i < 2:
print(0)
else:
print(sum(f[:i - 1]))
|
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22]]
| 5
| 109
|
from math import sqrt,floor
from sys import stdin
def cntPrime(n):
mx = sqrt(n)
if n % 2 == 0:
l = [0, 1] + [1, 0] * (int(n/2) - 1)
else:
l = [0, 1] + [1, 0] * (int(n/2) - 1) + [1]
c = 3
while c < mx:
for k in range(c*2, n+1, c):
l[k-1] = 0
c = l[(c+1):].index(1) + c +2
while c % 2 == 0:
c = l[(c+1):].index(1) + c +2
return l
t = cntPrime(1000000)
for n in stdin:
n = int(n)
print(sum(t[:n-1]))
|
from math import sqrt,floor
from sys import stdin
def cntPrime(n):
mx = sqrt(n)
if n % 2 == 0:
l = [0, 1] + [1, 0] * (int(n/2) - 1)
else:
l = [0, 1] + [1, 0] * (int(n/2) - 1) + [1]
c = 3
while c < mx:
for k in range(c*2, n+1, c):
l[k-1] = 0
c = l[(c+1):].index(1) + c +2
while c % 2 == 0:
c = l[(c+1):].index(1) + c +2
return l
t = cntPrime(1000000)
for n in stdin:
n = int(n)
print(sum(t[:n]))
|
[["-", 3, 4, 0, 206, 206, 663, 0, 657, 17, 33], ["-", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612]]
| 5
| 194
|
import sys
prime = [2,3,5,7,11,13,19,23,29,31]
shieve1 = [1]*1001
for i in prime:
itr = i-1
while(itr<1000):
shieve1[itr] = 0
itr += i
for i in range(32,1000):
if shieve1[i]:
prime.append(i+1)
shieve2 = [1]*(10**6+1)
for i in prime:
itr = i-1
while(itr<10**6):
shieve2[itr] = 0
itr += i
for i in range(1001,10**6+1):
if shieve2[i]:
prime.append(i+1)
for line in sys.stdin:
n = int(line)
cont = 0
for i in prime:
if i<=n:
cont += 1
else:
break
print(cont)
|
import sys
prime = [2,3,5,7,11,13,17,19,23,29,31]
shieve1 = [1]*1001
for i in prime:
itr = i-1
while(itr<1000):
shieve1[itr] = 0
itr += i
for i in range(32,1000):
if shieve1[i]:
prime.append(i+1)
shieve2 = [1]*(10**6+1)
for i in prime:
itr = i-1
while(itr<10**6):
shieve2[itr] = 0
itr += i
for i in range(1001,10**6+1):
if shieve2[i]:
prime.append(i+1)
for line in sys.stdin:
n = int(line)
cont = 0
for i in prime:
if i<=n:
cont += 1
else:
break
print(cont)
|
[["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 21]]
| 5
| 187
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
LIMIT = 1000000
is_prime = [True] * (LIMIT+1)
p = 2
while p**2 <= LIMIT:
if is_prime[p]:
for i in range(p*2, n+1, p):
is_prime[i] = False
p += 1
for line in sys.stdin.readlines():
n = int(line.strip())
if n <= 1:
print(0)
continue
if n == 2:
print(1)
continue
num_prime = 1
for i in range(3, n+1):
if is_prime[i]:
num_prime += 1
print(num_prime)
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
LIMIT = 1000000
is_prime = [True] * (LIMIT+1)
p = 2
while p**2 <= LIMIT:
if is_prime[p]:
for i in range(p*2, LIMIT+1, p):
is_prime[i] = False
p += 1
for line in sys.stdin.readlines():
n = int(line.strip())
if n <= 1:
print(0)
continue
if n == 2:
print(1)
continue
num_prime = 1
for i in range(3, n+1):
if is_prime[i]:
num_prime += 1
print(num_prime)
|
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22]]
| 5
| 128
|
import sys
import math as mas
def sieve(n):
p=[True for i in range(n+1)]
p[0]=p[1]=False
end=int(n**0.5)
for i in range(2,end+1):
if p[i]:
for j in range(i*i,n+1,i):
p[j]=False
return p
sosu=sieve(1000010)
for i in sys.stdin:
print(sum(sosu[t] for t in range(int(i))))
# a,b=map(int,i.split())
# print(gcd(a,b),lcm(a,b))
|
import sys
import math as mas
def sieve(n):
p=[True for i in range(n+1)]
p[0]=p[1]=False
end=int(n**0.5)
for i in range(2,end+1):
if p[i]:
for j in range(i*i,n+1,i):
p[j]=False
return p
sosu=sieve(1000010)
for i in sys.stdin:
print(sum(sosu[t] for t in range(int(i)+1)))
# a,b=map(int,i.split())
# print(gcd(a,b),lcm(a,b))
|
[["+", 0, 659, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 659, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 122
|
import sys
N = 999999
lis = []
if N >= 2:
lis.append(2)
if N >= 3:
lis.append(3)
if N >= 5:
for i in range(5,N+1,2):
for item in lis:
if item > (i**0.5):
lis.append(i)
break
if i % item == 0:
break
else:
lis.append(i)
dp = [0]*999999
for item in lis:
dp[item-1] += 1
for i in range(1,999999):
dp[i] += dp[i-1]
for line in sys.stdin:
num = int(line)
print(dp[line-1])
|
import sys
N = 999999
lis = []
if N >= 2:
lis.append(2)
if N >= 3:
lis.append(3)
if N >= 5:
for i in range(5,N+1,2):
for item in lis:
if item > (i**0.5):
lis.append(i)
break
if i % item == 0:
break
else:
lis.append(i)
dp = [0]*999999
for item in lis:
dp[item-1] += 1
for i in range(1,999999):
dp[i] += dp[i-1]
for line in sys.stdin:
num = int(line)
print(dp[num-1])
|
[["-", 0, 652, 3, 4, 0, 206, 206, 657, 31, 22], ["+", 0, 652, 3, 4, 0, 206, 206, 657, 31, 22]]
| 5
| 150
|
import sys
MAX = 999999
L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
def is_prime(n):
if n == 2:return True
if n % 2 == 0:return False
for i in range(3,int(n**0.5)+1,2):
if n % i == 0:return False
return True
def is_prime_2(n):
a = int(n ** 0.5)
for i in L:
if i > a:return True
if n % i == 0:return False
return True
def prime_count(n):
result = 0
if n >= 2:result+=1
for i in range(3,n+1,2):
if is_prime_2(i):result+=1
return result
def prime_list(n):
result = []
if n >= 2:result.append(2)
for i in range(3,n+1,2):
if is_prime(i):result.append(i)
return result
L2 = prime_list(MAX)
def prime_count_2(n):
for i,v in enumerate(L2):
if n > v:return i
return len(L2)
for n in sys.stdin:
print(prime_count_2(int(n)))
|
import sys
MAX = 999999
L = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
def is_prime(n):
if n == 2:return True
if n % 2 == 0:return False
for i in range(3,int(n**0.5)+1,2):
if n % i == 0:return False
return True
def is_prime_2(n):
a = int(n ** 0.5)
for i in L:
if i > a:return True
if n % i == 0:return False
return True
def prime_count(n):
result = 0
if n >= 2:result+=1
for i in range(3,n+1,2):
if is_prime_2(i):result+=1
return result
def prime_list(n):
result = []
if n >= 2:result.append(2)
for i in range(3,n+1,2):
if is_prime(i):result.append(i)
return result
L2 = prime_list(MAX)
def prime_count_2(n):
for i,v in enumerate(L2):
if v > n:return i
return len(L2)
for n in sys.stdin:
print(prime_count_2(int(n)))
|
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22]]
| 5
| 575
|
import sys
m=10**6;a=[1]*m;a[0:2]=0,0
for i in range(2,999):
if a[i]>0:
for j in range(i*2,m,i):a[j]=0
for e in sys.stdin:print(sum(a[:int(e)]))
|
import sys
m=10**6;a=[1]*m;a[0:2]=0,0
for i in range(2,999):
if a[i]>0:
for j in range(i*2,m,i):a[j]=0
for e in sys.stdin:print(sum(a[:int(e)+1]))
|
[["+", 3, 4, 0, 206, 206, 663, 0, 657, 17, 72], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612]]
| 5
| 85
|
import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
for j in range(2):
if (s[i],t[i])[j]:
k=6*i+[5,7][j];n=[i+k,k-i-2]
s[n[i]::k]=[0]*len(s[n[i]::k])
t[n[1-i]::k]=[0]*len(t[n[1-i]::k])
for e in map(int,sys.stdin):
print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3])
|
import sys
m=166666;s=[1]*m;t=[1]*m
for i in range(m):
for j in range(2):
if (s[i],t[i])[j]:
k=6*i+[5,7][j];n=[i+k,k-i-2]
s[n[j]::k]=[0]*len(s[n[j]::k])
t[n[1-j]::k]=[0]*len(t[n[1-j]::k])
for e in map(int,sys.stdin):
print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3])
|
[["-", 0, 662, 31, 206, 206, 663, 0, 206, 206, 22], ["+", 0, 662, 31, 206, 206, 663, 0, 206, 206, 22], ["-", 3, 4, 0, 206, 206, 663, 0, 206, 206, 22], ["+", 3, 4, 0, 206, 206, 663, 0, 206, 206, 22], ["-", 31, 206, 206, 663, 0, 206, 206, 657, 12, 22], ["+", 31, 206, 206, 663, 0, 206, 206, 657, 12, 22], ["-", 0, 206, 206, 663, 0, 206, 206, 657, 12, 22], ["+", 0, 206, 206, 663, 0, 206, 206, 657, 12, 22]]
| 5
| 198
|
LIMIT = 999999
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
for i in range(3, LIMIT + 1):
if prime[i - 1]:
for j in range(i ** 2, len(prime), i):
prime[j - 1] = 0
while True:
try:
n = int(input())
except EOFError:
break
print(n, sum(prime[:n]))
|
# coding: utf-8
LIMIT = 999999
prime = [0, 1] + [0 if i % 2 == 0 else 1 for i in range(3, LIMIT + 1)]
for i in range(3, LIMIT + 1):
if prime[i - 1]:
for j in range(i ** 2, LIMIT + 1, i):
prime[j - 1] = 0
while True:
try:
n = int(input())
except EOFError:
break
print(sum(prime[:n]))
|
[["-", 0, 7, 12, 652, 3, 4, 0, 652, 63, 22], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 21]]
| 5
| 108
|
#include <stdio.h>
#include <string.h>
#define STR_MAX 3
#define ASCII_BIAS 48
char h_adder(char n1, char n2, char *n3, char carry) {
char result = n1 + n2 + carry;
if (result < 10) {
*n3 = result + ASCII_BIAS;
return 0;
} else {
*n3 = result - 10 + ASCII_BIAS;
return 1;
}
}
int main(void) {
int i, j;
int dataset;
char in[2][STR_MAX + 2], out[STR_MAX + 2], result[STR_MAX + 2];
int len_in[2], idx_min, idx_max, lmin, lmax, lout, dif;
char carry;
char flg;
scanf("%d\n", &dataset);
for (i = 0; i < dataset; i++) {
flg = 0;
fgets(in[0], sizeof in[0], stdin);
len_in[0] = strlen(in[0]) - 1;
if (in[0][len_in[0]] != '\n') {
while (getchar() != '\n')
;
flg = 1;
}
fgets(in[1], sizeof in[1], stdin);
len_in[1] = strlen(in[1]) - 1;
if (in[1][len_in[1]] != '\n') {
while (getchar() != '\n')
;
flg = 1;
}
// check # of digits
if (flg) {
printf("overflow\n");
continue;
}
in[0][len_in[0]] = '\0';
in[1][len_in[1]] = '\0';
idx_min = (len_in[0] > len_in[1]) ? 1 : 0; // idx of shoter str
idx_max = (idx_min + 1) & 1; // idx of longer str
lmin = len_in[idx_min] - 1;
lmax = len_in[idx_max] - 1;
dif = (len_in[0] > len_in[1])
? len_in[0] - len_in[1]
: len_in[1] - len_in[0]; // difference in digits
// execute addition
carry = 0;
for (j = 0; j < lmin + 1; j++) {
carry =
h_adder(in[idx_min][lmin - j] - ASCII_BIAS,
in[idx_max][lmin - j + dif] - ASCII_BIAS, &out[j + 1], carry);
}
for (j = lmin + 1; j < lmax + 1; j++) {
carry = h_adder(0, in[idx_max][lmin - j + dif] - ASCII_BIAS, &out[j + 1],
carry);
}
// if carry is 0, validate overflow
if (carry == 1) {
if (lmax == STR_MAX - 1) {
printf("overflow\n");
continue;
}
}
lout = carry ? lmax + 2 : lmax + 1;
out[lmax + 2] = carry ? 1 + ASCII_BIAS : 0 + ASCII_BIAS;
// if overflow does not occur, addition succeeded
out[0] = '\0';
for (j = 0; j < lout + 1; j++) {
result[j] = out[lout - j];
}
printf("%s\n", result);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define STR_MAX 80
#define ASCII_BIAS 48
char h_adder(char n1, char n2, char *n3, char carry) {
char result = n1 + n2 + carry;
if (result < 10) {
*n3 = result + ASCII_BIAS;
return 0;
} else {
*n3 = result - 10 + ASCII_BIAS;
return 1;
}
}
int main(void) {
int i, j;
int dataset;
char in[2][STR_MAX + 2], out[STR_MAX + 2], result[STR_MAX + 2];
int len_in[2], idx_min, idx_max, lmin, lmax, lout, dif;
char carry;
char flg;
scanf("%d\n", &dataset);
for (i = 0; i < dataset; i++) {
flg = 0;
fgets(in[0], sizeof in[0], stdin);
len_in[0] = strlen(in[0]) - 1;
if (in[0][len_in[0]] != '\n') {
while (getchar() != '\n')
;
flg = 1;
}
fgets(in[1], sizeof in[1], stdin);
len_in[1] = strlen(in[1]) - 1;
if (in[1][len_in[1]] != '\n') {
while (getchar() != '\n')
;
flg = 1;
}
// check # of digits
if (flg) {
printf("overflow\n");
continue;
}
in[0][len_in[0]] = '\0';
in[1][len_in[1]] = '\0';
idx_min = (len_in[0] > len_in[1]) ? 1 : 0; // idx of shoter str
idx_max = (idx_min + 1) & 1; // idx of longer str
lmin = len_in[idx_min] - 1;
lmax = len_in[idx_max] - 1;
dif = (len_in[0] > len_in[1])
? len_in[0] - len_in[1]
: len_in[1] - len_in[0]; // difference in digits
// execute addition
carry = 0;
for (j = 0; j < lmin + 1; j++) {
carry =
h_adder(in[idx_min][lmin - j] - ASCII_BIAS,
in[idx_max][lmin - j + dif] - ASCII_BIAS, &out[j + 1], carry);
}
for (j = lmin + 1; j < lmax + 1; j++) {
carry = h_adder(0, in[idx_max][lmin - j + dif] - ASCII_BIAS, &out[j + 1],
carry);
}
// if carry is 0, validate overflow
if (carry == 1) {
if (lmax == STR_MAX - 1) {
printf("overflow\n");
continue;
}
}
lout = carry ? lmax + 2 : lmax + 1;
out[lmax + 2] = carry ? 1 + ASCII_BIAS : 0 + ASCII_BIAS;
// if overflow does not occur, addition succeeded
out[0] = '\0';
for (j = 0; j < lout + 1; j++) {
result[j] = out[lout - j];
}
printf("%s\n", result);
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 0
| 647
|
#include <stdio.h>
#include <string.h>
int main() {
char a[10000], b[10000];
int i, l, n, k = 0;
scanf("%d", &n);
while (n--) {
char c[81] = {0};
char d[81] = {0};
for (i = 0; i < 80; i++)
c[i] = d[i] = '0';
scanf("%s", a);
l = strlen(a); // printf("%d ",l);
if (l < 81)
strcpy(c + 80 - l, a); // printf("%s\n",c+80-l);
else
k = 1;
scanf("%s", b);
l = strlen(b); // printf("%d\n",l);
if (l < 81)
strcpy(d + 80 - l, b); // printf("%s\n",d+80-l);
else
k = 1;
if (k == 0) {
for (i = 79; i > -1; i--) { // printf("%c %c\n",c[i],d[i]);
d[i] = c[i] + d[i] + k - '0';
k = 0;
if (d[i] > '9') {
k = 1;
d[i] -= 10;
}
}
for (i = 0; i < 79; i++) {
if (d[i] != '0')
break;
}
}
if (k)
printf("ovreflow\n");
else
printf("%s\n", d + i);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
char a[10000], b[10000];
int i, l, n, k = 0;
scanf("%d", &n);
while (n--) {
char c[81] = {0};
char d[81] = {0};
k = 0;
for (i = 0; i < 80; i++)
c[i] = d[i] = '0';
scanf("%s", a);
l = strlen(a); // printf("%d ",l);
if (l < 81)
strcpy(c + 80 - l, a); // printf("%s\n",c+80-l);
else
k = 1;
scanf("%s", b);
l = strlen(b); // printf("%d\n",l);
if (l < 81)
strcpy(d + 80 - l, b); // printf("%s\n",d+80-l);
else
k = 1;
if (k == 0) {
for (i = 79; i > -1; i--) { // printf("%c %c\n",c[i],d[i]);
d[i] = c[i] + d[i] + k - '0';
k = 0;
if (d[i] > '9') {
k = 1;
d[i] -= 10;
}
}
for (i = 0; i < 79; i++) {
if (d[i] != '0')
break;
}
}
if (k)
printf("overflow\n");
else
printf("%s\n", d + i);
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 305
|
#include <stdio.h>
#include <string.h>
int main() {
char a[1000], b[1000];
int c[1000];
int i, j, k, l, m, n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < 90; j++) {
a[j] = '0';
b[j] = '0';
c[j] = 0;
}
scanf("%s", a);
scanf("%s", b);
j = strlen(a);
k = strlen(b);
// for(j=0; j<90; j++){
// if(a[j]=='\0'){
// a[j]='0';
// break;
// }
// }
// for(k=0; k<90; k++){
// if(b[k]=='\0'){
// b[k]='0';
// break;
// }
// }
if (j > k)
l = j;
else
l = k;
for (m = l; m > 0; m--) {
if (j - 1 >= 0)
c[m] += a[j - 1] - '0';
if (k - 1 >= 0)
c[m] += b[k - 1] - '0';
if (c[m] >= 10) {
c[m] -= 10;
c[m - 1] += 1;
}
j--;
k--;
}
if (l > 79 || (l == 79 && c[0] != 0))
printf("overflow\n");
else {
if (c[0] != 0)
printf("%d", c[0]);
for (j = 1; j <= l; j++)
printf("%d", c[j]);
printf("\n");
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
char a[1000], b[1000];
int c[1000];
int i, j, k, l, m, n;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < 90; j++) {
a[j] = '0';
b[j] = '0';
c[j] = 0;
}
scanf("%s", a);
scanf("%s", b);
j = strlen(a);
k = strlen(b);
// printf("j:%d\n",j);
// for(j=0; j<90; j++){
// if(a[j]=='\0'){
// a[j]='0';
// break;
// }
// }
// for(k=0; k<90; k++){
// if(b[k]=='\0'){
// b[k]='0';
// break;
// }
// }
if (j > k)
l = j;
else
l = k;
for (m = l; m > 0; m--) {
if (j - 1 >= 0)
c[m] += a[j - 1] - '0';
if (k - 1 >= 0)
c[m] += b[k - 1] - '0';
if (c[m] >= 10) {
c[m] -= 10;
c[m - 1] += 1;
}
j--;
k--;
}
// printf( "l:%d c:%d\n",l,c[0]);
if (l > 80 || (l == 80 && c[0] != 0))
printf("overflow\n");
else {
if (c[0] != 0)
printf("%d", c[0]);
for (j = 1; j <= l; j++)
printf("%d", c[j]);
printf("\n");
}
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["-", 0, 16, 12, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 13]]
| 0
| 346
|
#include <stdio.h>
#include <stdlib.h>
#define KETA 101
int main(void) {
int n = 0, i = 0, j = 0;
int *sum;
int goukei = 0;
int keta_max = 0;
int countsum = 0;
char *money1;
char *money2;
int count1 = 0, count2 = 0;
int *money_int1;
int *money_int2;
int t = 0, p = 0;
scanf("%d", &n);
for (t = 0; t < n; t++) {
money1 = (char *)malloc(sizeof(char) * KETA);
money2 = (char *)malloc(sizeof(char) * KETA);
money_int1 = (int *)malloc(sizeof(int) * KETA);
money_int2 = (int *)malloc(sizeof(int) * KETA);
sum = (int *)malloc(sizeof(int) * KETA);
/*for( p = 0; p < KETA; p++)
{
printf("m1:%d m2:%d sum:%d\n", money_int1[p], money_int2[p],
sum[p]);
}
printf("%s\n%s\n", money1, money2);
*/
for (i = 0; i < KETA; i++) {
money1[i] = '0';
money2[i] = '0';
money_int1[i] = 0;
money_int2[i] = 0;
sum[i] = 0;
}
scanf("%s", money1);
while (1) {
if (money1[count1] == '\0') {
break;
}
count1++;
}
scanf("%s", money2);
while (1) {
if (money2[count2] == '\0') {
break;
}
count2++;
}
j = count1 - 1;
for (i = 0; i < count1; i++) {
money_int1[j] = money1[i] - 0x30;
j--;
}
j = count2 - 1;
for (i = 0; i < count2; i++) {
money_int2[j] = money2[i] - 0x30;
j--;
}
i = 0;
if (count1 > count2) {
keta_max = count1;
} else {
keta_max = count2;
}
while (1) {
if ((i >= keta_max) && (money_int1[i] == 0 && money_int2[i] == 0)) {
countsum = i - 1;
break;
}
goukei = money_int1[i] + money_int2[i];
if (goukei >= 10) {
sum[i] = goukei % 10;
money_int1[i + 1] = money_int1[i + 1] + 1;
} else {
sum[i] = goukei;
}
i++;
}
for (i = countsum; i >= 0; i--) {
if (countsum > 80) {
printf("overflow\n");
break;
} else {
printf("%d", sum[i]);
}
}
printf("\n");
goukei = 0;
i = 0;
j = 0;
keta_max = 0;
countsum = 0;
count1 = 0;
count2 = 0;
free(money1);
free(money2);
free(sum);
free(money_int1);
free(money_int2);
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#define KETA 101
int main(void) {
int n = 0, i = 0, j = 0;
int *sum;
int goukei = 0;
int keta_max = 0;
int countsum = 0;
char *money1;
char *money2;
int count1 = 0, count2 = 0;
int *money_int1;
int *money_int2;
int t = 0, p = 0;
scanf("%d", &n);
for (t = 0; t < n; t++) {
money1 = (char *)malloc(sizeof(char) * KETA);
money2 = (char *)malloc(sizeof(char) * KETA);
money_int1 = (int *)malloc(sizeof(int) * KETA);
money_int2 = (int *)malloc(sizeof(int) * KETA);
sum = (int *)malloc(sizeof(int) * KETA);
/*for( p = 0; p < KETA; p++)
{
printf("m1:%d m2:%d sum:%d\n", money_int1[p], money_int2[p],
sum[p]);
}
printf("%s\n%s\n", money1, money2);
*/
for (i = 0; i < KETA; i++) {
money1[i] = '0';
money2[i] = '0';
money_int1[i] = 0;
money_int2[i] = 0;
sum[i] = 0;
}
scanf("%s", money1);
while (1) {
if (money1[count1] == '\0') {
break;
}
count1++;
}
scanf("%s", money2);
while (1) {
if (money2[count2] == '\0') {
break;
}
count2++;
}
j = count1 - 1;
for (i = 0; i < count1; i++) {
money_int1[j] = money1[i] - 0x30;
j--;
}
j = count2 - 1;
for (i = 0; i < count2; i++) {
money_int2[j] = money2[i] - 0x30;
j--;
}
i = 0;
if (count1 > count2) {
keta_max = count1;
} else {
keta_max = count2;
}
while (1) {
if ((i >= keta_max) && (money_int1[i] == 0 && money_int2[i] == 0)) {
countsum = i - 1;
break;
}
goukei = money_int1[i] + money_int2[i];
if (goukei >= 10) {
sum[i] = goukei % 10;
money_int1[i + 1] = money_int1[i + 1] + 1;
} else {
sum[i] = goukei;
}
i++;
}
for (i = countsum; i >= 0; i--) {
if (countsum > 79) {
printf("overflow");
break;
} else {
printf("%d", sum[i]);
}
}
printf("\n");
goukei = 0;
i = 0;
j = 0;
keta_max = 0;
countsum = 0;
count1 = 0;
count2 = 0;
free(money1);
free(money2);
free(sum);
free(money_int1);
free(money_int2);
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 610
|
#include <stdio.h>
#include <string.h>
#define MAX 180
#define LIMIT 180
int main() {
int n = 0;
int i = 0;
int j = 0;
int k = 0;
int a = 0;
char num1[MAX];
char num2[MAX];
int num1_int[MAX];
int num2_int[MAX];
int count1 = 0;
int count2 = 0;
int sum[MAX];
int ans[MAX];
scanf("%d", &n);
scanf("\n");
for (a = 0; a < n; a++) {
for (i = 0; i < MAX; i++) {
num1[i] = '\0';
num2[i] = '\0';
num1_int[i] = 0;
num2_int[i] = 0;
sum[i] = 0;
ans[i] = 0;
}
scanf("\n");
scanf("%s", num1);
scanf("\n");
scanf("%s", num2);
if (num1[0] == '0' && num2[0] == '0') {
printf("0\n");
continue;
}
//入力が79桁を超える場合
if (strlen(num1) > 79 || strlen(num2) > 79) {
printf("overflow\n");
continue;
}
//要素数の個数
while (1) {
if (num1[count1] == '\0') {
break;
}
count1++;
}
while (1) {
if (num2[count2] == '\0') {
break;
}
count2++;
}
// 16進数の整数を10進数の整数に変換
for (i = 0; i < count1; i++) {
num1_int[i] = num1[i] - 0x30;
/*printf("%d",num1_int[i]);*/
}
for (i = 0; i < count2; i++) {
num2_int[i] = num2[i] - 0x30;
// printf("%d",num2_int[i]);
}
//配列の右側に移動させ桁数を合わせる
for (i = 0; i < count1; i++) {
num1_int[LIMIT - count1 + i] = num1_int[i];
num1_int[i] = 0;
}
for (i = 0; i < count2; i++) {
num2_int[LIMIT - count2 + i] = num2_int[i];
num2_int[i] = 0;
}
/*
for(i = 0;i < count1;i++)
{
printf("%d",num1_int[i]);
}*/
for (i = LIMIT - 1; i >= 0; i--) {
sum[i] = num1_int[i] + num2_int[i];
//繰り上げ処理
if (sum[i] >= 10) {
num1_int[i - 1]++;
sum[i] -= 10;
}
}
for (i = 0; i < LIMIT; i++) {
if (sum[i] != 0) {
for (k = i; k < LIMIT; k++) {
ans[j] = sum[k];
// printf("%d",ans[j]);
j++;
}
break;
}
// printf("%d",sum[i]);
}
count1 = 0;
count2 = 0;
/*printf("j=%d\n",j);*/
if (j <= 79) {
for (i = 0; i < j; i++) {
printf("%d", ans[i]);
}
printf("\n");
} else if (j > 79) {
printf("overflow\n");
}
j = 0;
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define MAX 180
#define LIMIT 180
int main() {
int n = 0;
int i = 0;
int j = 0;
int k = 0;
int a = 0;
char num1[MAX];
char num2[MAX];
int num1_int[MAX];
int num2_int[MAX];
int count1 = 0;
int count2 = 0;
int sum[MAX];
int ans[MAX];
scanf("%d", &n);
scanf("\n");
for (a = 0; a < n; a++) {
for (i = 0; i < MAX; i++) {
num1[i] = '\0';
num2[i] = '\0';
num1_int[i] = 0;
num2_int[i] = 0;
sum[i] = 0;
ans[i] = 0;
}
scanf("\n");
scanf("%s", num1);
scanf("\n");
scanf("%s", num2);
if (num1[0] == '0' && num2[0] == '0') {
printf("0\n");
continue;
}
//入力が79桁を超える場合
if (strlen(num1) > 80 || strlen(num2) > 80) {
printf("overflow\n");
continue;
}
//要素数の個数
while (1) {
if (num1[count1] == '\0') {
break;
}
count1++;
}
while (1) {
if (num2[count2] == '\0') {
break;
}
count2++;
}
// 16進数の整数を10進数の整数に変換
for (i = 0; i < count1; i++) {
num1_int[i] = num1[i] - 0x30;
/*printf("%d",num1_int[i]);*/
}
for (i = 0; i < count2; i++) {
num2_int[i] = num2[i] - 0x30;
// printf("%d",num2_int[i]);
}
//配列の右側に移動させ桁数を合わせる
for (i = 0; i < count1; i++) {
num1_int[LIMIT - count1 + i] = num1_int[i];
num1_int[i] = 0;
}
for (i = 0; i < count2; i++) {
num2_int[LIMIT - count2 + i] = num2_int[i];
num2_int[i] = 0;
}
/*
for(i = 0;i < count1;i++)
{
printf("%d",num1_int[i]);
}*/
for (i = LIMIT - 1; i >= 0; i--) {
sum[i] = num1_int[i] + num2_int[i];
//繰り上げ処理
if (sum[i] >= 10) {
num1_int[i - 1]++;
sum[i] -= 10;
}
}
for (i = 0; i < LIMIT; i++) {
if (sum[i] != 0) {
for (k = i; k < LIMIT; k++) {
ans[j] = sum[k];
// printf("%d",ans[j]);
j++;
}
break;
}
// printf("%d",sum[i]);
}
count1 = 0;
count2 = 0;
/*printf("j=%d\n",j);*/
if (j <= 80) {
for (i = 0; i < j; i++) {
printf("%d", ans[i]);
}
printf("\n");
} else if (j > 80) {
printf("overflow\n");
}
j = 0;
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 645
|
#include <stdio.h>
#include <string.h>
void resetArray(int x[], int n) {
int i;
for (i = 0; i < n; i++)
x[i] = 0;
}
int main(void) {
char as[100], bs[100];
int a[100], b[100], c[100];
int n, ch, i, an, bn, abn, cn;
while (scanf("%d", &n) != EOF) {
while (n--) {
resetArray(a, 100);
resetArray(b, 100);
resetArray(c, 100);
scanf("%s", as);
scanf("%s", bs);
an = strlen(as);
bn = strlen(bs);
for (i = 0; i < an; i++)
a[i] = as[an - i - 1] - '0';
for (i = 0; i < bn; i++)
b[i] = bs[bn - i - 1] - '0';
abn = (an > bn) ? an : bn;
for (i = 0; i < abn; i++) {
c[i + 1] = (a[i] + b[i] + c[i]) / 10;
c[i] = (a[i] + b[i] + c[i]) % 10;
}
if (c[i])
cn = i + 1;
else
cn = i;
if (cn > 80) {
printf("overflow\n");
break;
} else
for (i = 0; i < cn; i++)
printf("%d", c[cn - i - 1]);
putchar('\n');
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
void resetArray(int x[], int n) {
int i;
for (i = 0; i < n; i++)
x[i] = 0;
}
int main(void) {
char as[100], bs[100];
int a[100], b[100], c[100];
int n, ch, i, an, bn, abn, cn;
while (scanf("%d", &n) != EOF) {
while (n--) {
resetArray(a, 100);
resetArray(b, 100);
resetArray(c, 100);
scanf("%s", as);
scanf("%s", bs);
an = strlen(as);
bn = strlen(bs);
for (i = 0; i < an; i++)
a[i] = as[an - i - 1] - '0';
for (i = 0; i < bn; i++)
b[i] = bs[bn - i - 1] - '0';
abn = (an > bn) ? an : bn;
for (i = 0; i < abn; i++) {
c[i + 1] = (a[i] + b[i] + c[i]) / 10;
c[i] = (a[i] + b[i] + c[i]) % 10;
}
if (c[i])
cn = i + 1;
else
cn = i;
if (cn > 80)
printf("overflow\n");
else {
for (i = 0; i < cn; i++)
printf("%d", c[cn - i - 1]);
putchar('\n');
}
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["-", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 0
| 380
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 1000000000
#define N 13
void changCode(char *num, int *a);
void addCode(int *a, int *b);
int main(void) {
int i, j, n, a[N], b[N];
char num1[101], num2[101];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", num1, num2);
changCode(num1, a);
changCode(num2, b);
addCode(a, b);
if (a[0] >= 9 && a[9] >= 10000000) {
printf("overflow\n");
} else {
for (j = a[0]; j > 0; j--) {
if (j != a[0]) {
printf("%09d", a[j]);
} else {
printf("%d", a[j]);
}
}
printf("\n");
}
}
return 0;
}
void changCode(char *num, int *a) {
int i, j, len;
char tmp[10];
len = strlen(num);
a[0] = (len % 9 == 0) ? len / 9 : len / 9 + 1;
for (i = 1; i < N; i++) {
a[i] = 0;
}
len--;
tmp[9] = '\0';
for (i = 1; i <= a[0]; i++) {
for (j = 8; j >= 0; j--) {
if (len >= 0) {
tmp[j] = num[len];
len--;
} else {
tmp[j] = '0';
}
}
a[i] = atoi(tmp);
}
}
void addCode(int *a, int *b) {
int i;
a[0] = (a[0] < b[0]) ? b[0] : a[0];
for (i = 1; i <= a[0]; i++) {
a[i] += b[i];
if (a[i] >= M) {
a[i] -= M;
a[i + 1]++;
if (i >= a[0]) {
a[0] = i + 1;
}
}
}
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 1000000000
#define N 13
void changCode(char *num, int *a);
void addCode(int *a, int *b);
int main(void) {
int i, j, n, a[N], b[N];
char num1[101], num2[101];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", num1, num2);
changCode(num1, a);
changCode(num2, b);
addCode(a, b);
if (a[0] >= 9 && a[9] >= M / 10) {
printf("overflow\n");
} else {
for (j = a[0]; j > 0; j--) {
if (j != a[0]) {
printf("%09d", a[j]);
} else {
printf("%d", a[j]);
}
}
printf("\n");
}
}
return 0;
}
void changCode(char *num, int *a) {
int i, j, len;
char tmp[10];
len = strlen(num);
a[0] = (len % 9 == 0) ? len / 9 : len / 9 + 1;
for (i = 1; i < N; i++) {
a[i] = 0;
}
len--;
tmp[9] = '\0';
for (i = 1; i <= a[0]; i++) {
for (j = 8; j >= 0; j--) {
if (len >= 0) {
tmp[j] = num[len];
len--;
} else {
tmp[j] = '0';
}
}
a[i] = atoi(tmp);
}
}
void addCode(int *a, int *b) {
int i;
a[0] = (a[0] < b[0]) ? b[0] : a[0];
for (i = 1; i <= a[0]; i++) {
a[i] += b[i];
if (a[i] >= M) {
a[i] -= M;
a[i + 1]++;
if (i >= a[0]) {
a[0] = i + 1;
}
}
}
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 17, 85], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 12, 13]]
| 0
| 506
|
#include <stdio.h>
#include <string.h>
int main(void) {
char sa[100], sb[100];
int ra[100], rb[100], t[101];
int la, lb;
int N;
int i, j, k;
int a = 0;
for (i = 0; i < 101; i++) {
t[i] = 0;
}
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%s", &sa);
scanf("%s", &sb);
la = strlen(sa);
if (la > 80) {
printf("overflow\n");
} else {
lb = strlen(sb);
if (lb > 80) {
printf("overflow\n");
} else {
//?????¢
for (j = 0; j < la; j++) {
ra[j] = sa[la - 1 - j] - 48;
}
for (j = la; j < 100; j++) {
ra[j] = 0;
}
for (j = 0; j < lb; j++) {
rb[j] = sb[lb - 1 - j] - 48;
}
for (j = lb; j < 100; j++) {
rb[j] = 0;
}
//?¶???????????¨????
for (j = 0; j < 100; j++) {
// printf("/???//%d %d %d %d\n", ra[j], rb[j], t[j], t[j + 1]);
t[j] = (a + ra[j] + rb[j]) % 10;
a = (a + ra[j] + rb[j]) / 10;
// printf("/???//%d %d %d %d\n", ra[j], rb[j], t[j], t[j + 1]);
}
//??????
j = 100;
while (j > 0) {
if (t[j] != 0) {
break;
}
j--;
}
if (j > 80) {
printf("overflow\n");
} else {
for (k = j; k >= 0; k--) {
printf("%d", t[k]);
}
printf("\n");
}
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main(void) {
char sa[100], sb[100];
int ra[100], rb[100], t[101];
int la, lb;
int N;
int i, j, k;
int a = 0;
for (i = 0; i < 101; i++) {
t[i] = 0;
}
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%s", &sa);
scanf("%s", &sb);
la = strlen(sa);
if (la > 80) {
printf("overflow\n");
} else {
lb = strlen(sb);
if (lb > 80) {
printf("overflow\n");
} else {
//?????¢
for (j = 0; j < la; j++) {
ra[j] = sa[la - 1 - j] - 48;
}
for (j = la; j < 100; j++) {
ra[j] = 0;
}
for (j = 0; j < lb; j++) {
rb[j] = sb[lb - 1 - j] - 48;
}
for (j = lb; j < 100; j++) {
rb[j] = 0;
}
//?¶???????????¨????
for (j = 0; j < 100; j++) {
// printf("/???//%d %d %d %d\n", ra[j], rb[j], t[j], t[j + 1]);
t[j] = (a + ra[j] + rb[j]) % 10;
a = (a + ra[j] + rb[j]) / 10;
// printf("/???//%d %d %d %d\n", ra[j], rb[j], t[j], t[j + 1]);
}
//??????
j = 100;
while (j > 0) {
if (t[j] != 0) {
break;
}
j--;
}
if (j >= 80) {
printf("overflow\n");
} else {
for (k = j; k >= 0; k--) {
printf("%d", t[k]);
}
printf("\n");
}
}
}
}
return 0;
}
|
[["-", 0, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 0, 9, 0, 57, 15, 23, 0, 16, 17, 20]]
| 0
| 426
|
#include <stdio.h>
#include <string.h>
#define MAX_LEN 100
#define MAX_LEN1 (MAX_LEN + 1)
#define LABEL_OVERFLOW "overflow"
int main() {
char in1[MAX_LEN1], in2[MAX_LEN1], out[MAX_LEN1];
int len1, len2, len, i1, i2, o, carry, i, j, n;
scanf("%d", &n);
for (j = 0; j < n; j++) {
scanf("%s", in1);
scanf("%s", in2);
if ((len1 = strlen(in1)) > 80 || (len2 = strlen(in2)) > 80) {
printf("%s\n", LABEL_OVERFLOW);
continue;
}
if (len1 > len2)
len = len1;
else
len = len2;
out[len] = '\0';
for (i = 0, carry = 0; i < len; i++) {
out[len - i - 1] = '0';
if (len1 - i - 1 < 0)
i1 = 0;
else
i1 = in1[len1 - i - 1] - '0';
if (len2 - i - 1 < 0)
i2 = 0;
else
i2 = in2[len2 - i - 1] - '0';
if ((o = i1 + i2 + carry) >= 10) {
carry = 1;
o -= 10;
} else
carry = 0;
out[len - i - 1] = o + '0';
}
if (carry > 0) {
if (len >= 80)
strcpy(out, LABEL_OVERFLOW);
else
printf("1%s\n", out);
} else
printf("%s\n", out);
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define MAX_LEN 100
#define MAX_LEN1 (MAX_LEN + 1)
#define LABEL_OVERFLOW "overflow"
int main() {
char in1[MAX_LEN1], in2[MAX_LEN1], out[MAX_LEN1];
int len1, len2, len, i1, i2, o, carry, i, j, n;
scanf("%d", &n);
for (j = 0; j < n; j++) {
scanf("%s", in1);
scanf("%s", in2);
if ((len1 = strlen(in1)) > 80 || (len2 = strlen(in2)) > 80) {
printf("%s\n", LABEL_OVERFLOW);
continue;
}
if (len1 > len2)
len = len1;
else
len = len2;
out[len] = '\0';
for (i = 0, carry = 0; i < len; i++) {
out[len - i - 1] = '0';
if (len1 - i - 1 < 0)
i1 = 0;
else
i1 = in1[len1 - i - 1] - '0';
if (len2 - i - 1 < 0)
i2 = 0;
else
i2 = in2[len2 - i - 1] - '0';
if ((o = i1 + i2 + carry) >= 10) {
carry = 1;
o -= 10;
} else
carry = 0;
out[len - i - 1] = o + '0';
}
if (carry > 0) {
if (len >= 80)
printf("%s\n", LABEL_OVERFLOW);
else
printf("1%s\n", out);
} else
printf("%s\n", out);
}
return 0;
}
|
[["-", 64, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 64, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["-", 0, 57, 64, 1, 0, 2, 3, 4, 0, 22], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 343
|
#include <stdio.h>
#include <string.h>
#define MAX 80
char a[MAX + 1], b[MAX + 1];
int sum[MAX + 1];
int a_size, b_size, sum_size;
void culc(int carry) {
if (sum_size < a_size && sum_size < b_size)
sum[sum_size] =
a[a_size - sum_size - 1] - '0' + b[b_size - sum_size - 1] - '0' + carry;
else if (sum_size >= a_size && sum_size < b_size)
sum[sum_size] = b[b_size - sum_size - 1] - '0' + carry;
else if (sum_size < a_size && sum_size >= b_size)
sum[sum_size] = a[a_size - sum_size - 1] - '0' + carry;
else if (sum_size >= a_size && sum_size >= b_size)
sum[sum_size] = carry;
if (sum[sum_size] > 9) {
sum[sum_size] -= 10;
carry = 1;
} else {
carry = 0;
}
if ((++sum_size < a_size || sum_size < b_size) || carry == 1)
culc(carry);
return;
}
int main(void) {
int n, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", a, b);
a_size = strlen(a);
b_size = strlen(b);
if (a_size >= MAX + 1 || b_size >= MAX + 1) {
printf("overflow\n");
continue;
}
sum_size = 0;
culc(0);
if (sum_size > MAX) {
printf("overflow2\n");
continue;
} else {
for (sum_size--; sum_size >= 0; sum_size--) {
printf("%d", sum[sum_size]);
}
printf("\n");
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define MAX 80
char a[MAX + 1], b[MAX + 1];
int sum[MAX + 1];
int a_size, b_size, sum_size;
void culc(int carry) {
if (sum_size < a_size && sum_size < b_size)
sum[sum_size] =
a[a_size - sum_size - 1] - '0' + b[b_size - sum_size - 1] - '0' + carry;
else if (sum_size >= a_size && sum_size < b_size)
sum[sum_size] = b[b_size - sum_size - 1] - '0' + carry;
else if (sum_size < a_size && sum_size >= b_size)
sum[sum_size] = a[a_size - sum_size - 1] - '0' + carry;
else if (sum_size >= a_size && sum_size >= b_size)
sum[sum_size] = carry;
if (sum[sum_size] > 9) {
sum[sum_size] -= 10;
carry = 1;
} else {
carry = 0;
}
if ((++sum_size < a_size || sum_size < b_size) || carry == 1)
culc(carry);
return;
}
int main(void) {
int n, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", a, b);
a_size = strlen(a);
b_size = strlen(b);
if (a_size >= MAX + 1 || b_size >= MAX + 1) {
printf("overflow\n");
continue;
}
sum_size = 0;
culc(0);
if (sum_size > MAX) {
printf("overflow\n");
continue;
} else {
for (sum_size--; sum_size >= 0; sum_size--) {
printf("%d", sum[sum_size]);
}
printf("\n");
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 377
|
#include <stdio.h>
int main(void) {
int a[80];
int b[80];
int result[80];
int ketaagari;
int i, j;
int max;
int temp[80];
char in;
int overflow;
int count, kazu;
scanf("%d", &kazu);
while (getchar() != '\n')
;
for (count = 0; count < kazu; count++) {
for (i = 0; i < 80; i++) {
a[i] = 0;
b[i] = 0;
}
i = 0;
overflow = 0;
while ((in = getchar()) != '\n') {
temp[i] = in - '0';
i++;
if (i >= 80) {
overflow = 1;
while (getchar() != '\n')
;
break;
}
}
if (overflow == 0) {
for (j = 0; j < i; j++)
a[j] = temp[i - j - 1];
}
i = 0;
while ((in = getchar()) != '\n') {
temp[i] = in - '0';
i++;
if (i >= 80) {
overflow = 1;
while (getchar() != '\n')
;
break;
}
}
if (overflow == 0) {
for (j = 0; j < i; j++)
b[j] = temp[i - j - 1];
for (i = 0, ketaagari = 0, max = 0; i < 80; i++) {
result[i] = (a[i] + b[i] + ketaagari) % 10;
ketaagari = (a[i] + b[i] + ketaagari) / 10;
if (result[i] != 0)
max = i;
}
if (ketaagari)
overflow = 1;
}
if (overflow == 0) {
for (i = max; i >= 0; i--)
printf("%d", result[i]);
printf("\n");
} else
printf("overflow\n");
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a[80];
int b[80];
int result[80];
int ketaagari;
int i, j;
int max;
int temp[80];
char in;
int overflow;
int count, kazu;
scanf("%d", &kazu);
while (getchar() != '\n')
;
for (count = 0; count < kazu; count++) {
for (i = 0; i < 80; i++) {
a[i] = 0;
b[i] = 0;
}
i = 0;
overflow = 0;
while ((in = getchar()) != '\n') {
temp[i] = in - '0';
i++;
if (i > 80) {
overflow = 1;
while (getchar() != '\n')
;
break;
}
}
if (overflow == 0) {
for (j = 0; j < i; j++)
a[j] = temp[i - j - 1];
}
i = 0;
while ((in = getchar()) != '\n') {
temp[i] = in - '0';
i++;
if (i > 80) {
overflow = 1;
while (getchar() != '\n')
;
break;
}
}
if (overflow == 0) {
for (j = 0; j < i; j++)
b[j] = temp[i - j - 1];
for (i = 0, ketaagari = 0, max = 0; i < 80; i++) {
result[i] = (a[i] + b[i] + ketaagari) % 10;
ketaagari = (a[i] + b[i] + ketaagari) / 10;
if (result[i] != 0)
max = i;
}
if (ketaagari)
overflow = 1;
}
if (overflow == 0) {
for (i = max; i >= 0; i--)
printf("%d", result[i]);
printf("\n");
} else
printf("overflow\n");
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47]]
| 0
| 447
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char a[82], b[82];
int ans[81];
int a_len, b_len;
int a_num, b_num, ans_num, agari;
int setsize, keta;
int i, j;
scanf("%d", &setsize);
for (i = 0; i < setsize; i++) {
scanf("%81s%*", a);
scanf("%81s%*", b);
if ((a_len = strlen(a)) > 80 || (b_len = strlen(b)) > 80) {
printf("overflow\n");
continue;
}
agari = 0;
for (j = 0; j < 81; j++) {
a_num = 0;
b_num = 0;
if (a_len > 0) {
a_num = atoi(&a[a_len - 1]);
a[a_len - 1] = '\0';
a_len--;
}
if (b_len > 0) {
b_num = atoi(&b[b_len - 1]);
b[b_len - 1] = '\0';
b_len--;
}
ans_num = a_num + b_num + agari;
if (ans_num > 9) {
agari = 1;
ans_num %= 10;
} else
agari = 0;
ans[j] = ans_num;
}
if (ans[80] > 0) {
printf("overflow\n");
continue;
}
for (keta = 80; keta > 0; keta--) {
if (ans[keta] > 0)
break;
}
for (i = keta; i > 0; i--) {
printf("%d", ans[i]);
}
printf("%d\n", ans[0]);
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char a[82], b[82];
int ans[81];
int a_len, b_len;
int a_num, b_num, ans_num, agari;
int setsize, keta;
int i, j;
scanf("%d", &setsize);
for (i = 0; i < setsize; i++) {
scanf("%81s%*", a);
scanf("%81s%*", b);
if ((a_len = strlen(a)) > 80 || (b_len = strlen(b)) > 80) {
printf("overflow\n");
continue;
}
agari = 0;
for (j = 0; j < 81; j++) {
a_num = 0;
b_num = 0;
if (a_len > 0) {
a_num = atoi(&a[a_len - 1]);
a[a_len - 1] = '\0';
a_len--;
}
if (b_len > 0) {
b_num = atoi(&b[b_len - 1]);
b[b_len - 1] = '\0';
b_len--;
}
ans_num = a_num + b_num + agari;
if (ans_num > 9) {
agari = 1;
ans_num %= 10;
} else
agari = 0;
ans[j] = ans_num;
}
if (ans[80] > 0) {
printf("overflow\n");
continue;
}
for (keta = 80; keta > 0; keta--) {
if (ans[keta] > 0)
break;
}
for (j = keta; j > 0; j--) {
printf("%d", ans[j]);
}
printf("%d\n", ans[0]);
}
return 0;
}
|
[["-", 0, 7, 8, 9, 0, 7, 10, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 10, 11, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22]]
| 0
| 355
|
// ツ堕スツ倍ツ陳キツ可可算
#include <stdio.h>
#include <string.h>
#define MAX_LEN (80)
int main(void) {
int no;
scanf("%d", &no);
while (no--) {
char num_str[MAX_LEN + 2];
char add_str[MAX_LEN + 2];
int num_len, add_len;
int i;
int tmp;
scanf("%80s", num_str);
scanf("%80s", add_str);
num_len = strlen(num_str);
add_len = strlen(add_str);
memmove(&num_str[MAX_LEN - num_len + 1], num_str, num_len);
for (i = 0; i < MAX_LEN - num_len + 1; i++)
num_str[i] = '0';
num_str[MAX_LEN + 1] = '\0';
memmove(&add_str[MAX_LEN - add_len + 1], add_str, add_len);
for (i = 0; i < MAX_LEN - add_len + 1; i++)
add_str[i] = '0';
add_str[MAX_LEN + 1] = '\0';
tmp = 0;
for (i = MAX_LEN; i + 1; i--) {
num_str[i] = num_str[i] + (add_str[i] - '0') + tmp;
if (num_str[i] > '9') {
num_str[i] = num_str[i] - 10;
tmp = 1;
} else
tmp = 0;
}
if (num_str[0] != '0')
puts("overflow");
else {
for (i = 1; num_str[i] == '0'; i++)
;
if (i == MAX_LEN + 1)
puts("0");
else
puts(&num_str[i]);
}
}
return (0);
}
|
// ツ堕スツ倍ツ陳キツ可可算
#include <stdio.h>
#include <string.h>
#define MAX_LEN (80)
int main(void) {
int no;
scanf("%d", &no);
while (no--) {
char num_str[MAX_LEN + 2];
char add_str[MAX_LEN + 2];
int num_len, add_len;
int i;
int tmp;
scanf("%81s", num_str);
scanf("%81s", add_str);
num_len = strlen(num_str);
add_len = strlen(add_str);
memmove(&num_str[MAX_LEN - num_len + 1], num_str, num_len);
for (i = 0; i < MAX_LEN - num_len + 1; i++)
num_str[i] = '0';
num_str[MAX_LEN + 1] = '\0';
memmove(&add_str[MAX_LEN - add_len + 1], add_str, add_len);
for (i = 0; i < MAX_LEN - add_len + 1; i++)
add_str[i] = '0';
add_str[MAX_LEN + 1] = '\0';
tmp = 0;
for (i = MAX_LEN; i + 1; i--) {
num_str[i] = num_str[i] + (add_str[i] - '0') + tmp;
if (num_str[i] > '9') {
num_str[i] = num_str[i] - 10;
tmp = 1;
} else
tmp = 0;
}
if (num_str[0] != '0')
puts("overflow");
else {
for (i = 1; num_str[i] == '0'; i++)
;
if (i == MAX_LEN + 1)
puts("0");
else
puts(&num_str[i]);
}
}
return (0);
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 348
|
#include <stdio.h>
#include <string.h>
#define DIGIT (80)
int main() {
int i, j, n, temp, overFlow = 0;
char num[2][DIGIT + 1];
char ans[DIGIT + 2];
char fmt[8];
int len[2], index;
// scanf format
sprintf(fmt, "%%%ds", DIGIT);
scanf("%d", &n);
for (i = 0; i < n; ++i) {
overFlow = 0;
for (j = 0; !overFlow && j < 2; ++j) {
scanf(fmt, num[j]);
while (getchar() != '\n')
overFlow = 1;
len[j] = strlen(num[j]);
// printf("num : %s\nlen : %d\n", num[j], len[j]);
}
if (overFlow) {
puts("overflow");
continue;
}
// bigger one
index = (len[0] < len[1]) ? 1 : 0;
ans[0] = ans[len[index] + 1] = '\0';
temp = 0;
for (j = 1; j <= len[index ^ 1]; ++j) {
temp += (num[0][len[0] - j] - '0') + (num[1][len[1] - j] - '0');
ans[len[index] - j + 1] = temp % 10 + '0';
temp /= 10;
}
for (; j <= len[index]; ++j) {
temp += (num[index][len[index] - j] - '0');
ans[len[index] - j + 1] = temp % 10 + '0';
temp /= 10;
}
if (temp) {
if (len[index] == DIGIT) {
puts("overflow");
} else {
ans[0] = '1';
puts(ans);
}
} else {
puts(ans + 1);
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define DIGIT (80)
int main() {
int i, j, n, temp, overFlow = 0;
char num[2][DIGIT + 1];
char ans[DIGIT + 2];
char fmt[8];
int len[2], index;
// scanf format
sprintf(fmt, "%%%ds", DIGIT);
scanf("%d", &n);
for (i = 0; i < n; ++i) {
overFlow = 0;
for (j = 0; j < 2; ++j) {
scanf(fmt, num[j]);
while (getchar() != '\n')
overFlow = 1;
len[j] = strlen(num[j]);
// printf("num : %s\nlen : %d\n", num[j], len[j]);
}
if (overFlow) {
puts("overflow");
continue;
}
// bigger one
index = (len[0] < len[1]) ? 1 : 0;
ans[0] = ans[len[index] + 1] = '\0';
temp = 0;
for (j = 1; j <= len[index ^ 1]; ++j) {
temp += (num[0][len[0] - j] - '0') + (num[1][len[1] - j] - '0');
ans[len[index] - j + 1] = temp % 10 + '0';
temp /= 10;
}
for (; j <= len[index]; ++j) {
temp += (num[index][len[index] - j] - '0');
ans[len[index] - j + 1] = temp % 10 + '0';
temp /= 10;
}
if (temp) {
if (len[index] == DIGIT) {
puts("overflow");
} else {
ans[0] = '1';
puts(ans);
}
} else {
puts(ans + 1);
}
}
return 0;
}
|
[["-", 8, 9, 0, 7, 15, 16, 31, 91, 17, 111], ["-", 8, 9, 0, 7, 15, 16, 31, 91, 28, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 98]]
| 0
| 411
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
const int START = 500;
int n, anssize;
char xstr[1000], ystr[1000], answer[100];
scanf("%d", &n);
while (n > 0) {
anssize = 99;
answer[anssize--] = '\0';
memset(xstr, '0', 200);
memset(ystr, '0', 200);
scanf("%s", &xstr[START]);
scanf("%s", &ystr[START]);
int xsize = strlen(&xstr[START]) - 1;
int ysize = strlen(&ystr[START]) - 1;
int carry = 0;
while (xsize >= 0 || ysize >= 0) {
int x = xstr[START + xsize--] - '0' + ystr[START + ysize--] - '0' + carry;
answer[anssize--] = (x % 10) + '0';
carry = x / 10;
}
if (carry) {
answer[anssize--] = '1';
}
if (anssize > 17) {
printf("%s\n", &answer[anssize + 1]);
} else {
printf("overflow\n");
}
n--;
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
const int START = 500;
int n, anssize;
char xstr[1000], ystr[1000], answer[1000];
scanf("%d", &n);
while (n > 0) {
anssize = 999;
answer[anssize--] = '\0';
memset(xstr, '0', 1000);
memset(ystr, '0', 1000);
scanf("%s", &xstr[START]);
scanf("%s", &ystr[START]);
int xsize = strlen(&xstr[START]) - 1;
int ysize = strlen(&ystr[START]) - 1;
int carry = 0;
while (xsize >= 0 || ysize >= 0) {
int x = xstr[START + xsize--] - '0' + ystr[START + ysize--] - '0' + carry;
answer[anssize--] = (x % 10) + '0';
carry = x / 10;
}
if (carry) {
answer[anssize--] = '1';
}
if (anssize > 917) {
printf("%s\n", &answer[anssize + 1]);
} else {
printf("overflow\n");
}
n--;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 273
|
#include <stdio.h>
#define MAX_DIGIT 80
void initialize(int a[]) {
int i;
for (i = 0; i < MAX_DIGIT; i++)
a[i] = 0;
}
void reverse(int a[], int n) {
int i, temp[MAX_DIGIT];
for (i = 0; i < n; i++)
temp[i] = a[i];
for (i = 0; i < n; i++)
a[i] = temp[n - 1 - i];
}
int input_number(int a[]) {
int num_digit = 0;
char digit;
while ((digit = getchar()) != '\n') {
if (num_digit == MAX_DIGIT) {
while (getchar() != '\n')
;
return -1;
}
a[num_digit++] = digit - '0';
}
reverse(a, num_digit);
return num_digit;
}
int add(int a[], int b[], int na, int nb, int result[]) {
int i, n, num_digit;
n = na > nb ? na : nb;
for (i = 0; i < n; i++)
result[i] = a[i] + b[i];
for (i = 0; i < n; i++) {
if (result[i] > 9) {
if (i == MAX_DIGIT - 1)
return 0;
else {
result[i] -= 10;
result[i + 1]++;
num_digit = i + 2;
}
} else
num_digit = i + 1;
}
reverse(result, num_digit);
return num_digit;
}
int main(void) {
int i, n, na, nb, nr;
int a[MAX_DIGIT], b[MAX_DIGIT], result[MAX_DIGIT];
scanf("%d", &n);
while (getchar() != '\n')
;
while (n--) {
initialize(a);
initialize(b);
initialize(result);
na = input_number(a);
nb = input_number(b);
if (na == -1 || nb == -1) {
printf("overflow\n");
continue;
}
nr = add(a, b, na, nb, result);
if (nr == -1) {
printf("overflow");
continue;
}
for (i = 0; i < nr; i++)
printf("%d", result[i]);
printf("\n");
}
return 0;
}
|
#include <stdio.h>
#define MAX_DIGIT 80
void initialize(int a[]) {
int i;
for (i = 0; i < MAX_DIGIT; i++)
a[i] = 0;
}
void reverse(int a[], int n) {
int i, temp[MAX_DIGIT];
for (i = 0; i < n; i++)
temp[i] = a[i];
for (i = 0; i < n; i++)
a[i] = temp[n - 1 - i];
}
int input_number(int a[]) {
int num_digit = 0;
char digit;
while ((digit = getchar()) != '\n') {
if (num_digit == MAX_DIGIT) {
while (getchar() != '\n')
;
return -1;
}
a[num_digit++] = digit - '0';
}
reverse(a, num_digit);
return num_digit;
}
int add(int a[], int b[], int na, int nb, int result[]) {
int i, n, num_digit;
n = na > nb ? na : nb;
for (i = 0; i < n; i++)
result[i] = a[i] + b[i];
for (i = 0; i < n; i++) {
if (result[i] > 9) {
if (i == MAX_DIGIT - 1)
return -1;
else {
result[i] -= 10;
result[i + 1]++;
num_digit = i + 2;
}
} else
num_digit = i + 1;
}
reverse(result, num_digit);
return num_digit;
}
int main(void) {
int i, n, na, nb, nr;
int a[MAX_DIGIT], b[MAX_DIGIT], result[MAX_DIGIT];
scanf("%d", &n);
while (getchar() != '\n')
;
while (n--) {
initialize(a);
initialize(b);
initialize(result);
na = input_number(a);
nb = input_number(b);
if (na == -1 || nb == -1) {
printf("overflow\n");
continue;
}
nr = add(a, b, na, nb, result);
if (nr == -1) {
printf("overflow\n");
continue;
}
for (i = 0; i < nr; i++)
printf("%d", result[i]);
printf("\n");
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 57, 64, 37, 0, 13], ["+", 0, 57, 64, 9, 0, 57, 64, 37, 0, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 516
|
#include <stdio.h>
#include <string.h>
#define STR_SIZE 100
int add_bignum(char a[], char b[], char out[]) {
int alen = strlen(a);
int blen = strlen(b);
if (alen >= 80 || blen >= 80) {
return 0;
}
char buf[STR_SIZE] = "";
--alen;
--blen;
int i, digit, tmp = 0;
for (i = 0; i < 100; i++) {
if (alen >= 0 && blen >= 0)
digit = (int)a[alen] + (int)b[blen] - '0' - '0';
else if (alen >= 0 && blen < 0)
digit = a[alen] - '0';
else if (alen < 0 && blen >= 0)
digit = b[blen] - '0';
digit += tmp;
buf[i] = (char)((digit % 10) + '0');
tmp = (char)(digit / 10) & 1;
--alen;
--blen;
if (alen < 0 && blen < 0)
break;
}
if (tmp) {
buf[++i] = '1';
}
int clen = strlen(buf);
if (clen >= 80) {
return 0;
}
--clen;
for (i = 0; clen >= 0; clen--, i++) {
out[i] = buf[clen];
}
out[i] = '\0';
return 1;
}
int main() {
int n;
char a[STR_SIZE], b[STR_SIZE], c[STR_SIZE];
scanf("%d", &n);
for (; n; n--) {
scanf(" %100s %100s", a, b);
if (!add_bignum(a, b, c)) {
puts("overflow");
} else {
puts(c);
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define STR_SIZE 100
int add_bignum(char a[], char b[], char out[]) {
int alen = strlen(a);
int blen = strlen(b);
if (alen >= 81 || blen >= 81) {
return 0;
}
char buf[STR_SIZE] = "";
--alen;
--blen;
int i, digit, tmp = 0;
for (i = 0; i < 100; i++) {
if (alen >= 0 && blen >= 0)
digit = (int)a[alen] + (int)b[blen] - '0' - '0';
else if (alen >= 0 && blen < 0)
digit = a[alen] - '0';
else if (alen < 0 && blen >= 0)
digit = b[blen] - '0';
digit += tmp;
buf[i] = (char)((digit % 10) + '0');
tmp = (char)(digit / 10) & 1;
--alen;
--blen;
if (alen < 0 && blen < 0)
break;
}
if (tmp) {
buf[++i] = '1';
}
int clen = strlen(buf);
if (clen >= 81) {
return 0;
}
--clen;
for (i = 0; clen >= 0; clen--, i++) {
out[i] = buf[clen];
}
out[i] = '\0';
return 1;
}
int main() {
int n;
char a[STR_SIZE], b[STR_SIZE], c[STR_SIZE];
scanf("%d", &n);
for (; n; n--) {
scanf(" %100s %100s", a, b);
if (!add_bignum(a, b, c)) {
puts("overflow");
} else {
puts(c);
}
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 398
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <malloc.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 1024
void convert(char num[LEN], int a[LEN]);
void add(int a[LEN], int b[LEN], int c[LEN]);
void printLDV(int c[LEN]);
int main() {
int i, n, a[LEN], b[LEN], c[LEN];
char num1[LEN], num2[LEN];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", num1);
scanf("%s", num2);
convert(num1, a);
convert(num2, b);
add(a, b, c);
printLDV(c);
}
return 0;
}
void convert(char num[LEN], int x[LEN]) {
int i;
for (i = 0; i < LEN; i++)
x[i] = 0;
for (i = strlen(num) - 1; i >= 0; i--) {
x[LEN + i - (strlen(num) - 1) - 1] = num[i] - '0';
}
return;
}
void add(int a[LEN], int b[LEN], int c[LEN]) {
int i;
for (i = 0; i < LEN; i++)
c[i] = 0;
for (i = LEN - 1; i >= 1; i--) {
c[i] += a[i] + b[i];
if (c[i] >= 10) {
c[i] = c[i] % 10;
c[i - 1] = 1;
}
}
return;
}
void printLDV(int c[LEN]) {
int i, flag = 0;
for (i = 0; i < LEN; i++) {
if (i <= LEN - 80) {
if (c[i] != 0) {
printf("overflow");
flag = 1;
break;
}
} else {
if (c[i] != 0)
flag = 1;
if (flag == 1)
printf("%d", c[i]);
}
}
if (flag == 0)
printf("0");
printf("\n");
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <malloc.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 1024
void convert(char num[LEN], int a[LEN]);
void add(int a[LEN], int b[LEN], int c[LEN]);
void printLDV(int c[LEN]);
int main() {
int i, n, a[LEN], b[LEN], c[LEN];
char num1[LEN], num2[LEN];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", num1);
scanf("%s", num2);
convert(num1, a);
convert(num2, b);
add(a, b, c);
printLDV(c);
}
return 0;
}
void convert(char num[LEN], int x[LEN]) {
int i;
for (i = 0; i < LEN; i++)
x[i] = 0;
for (i = strlen(num) - 1; i >= 0; i--) {
x[LEN + i - (strlen(num) - 1) - 1] = num[i] - '0';
}
return;
}
void add(int a[LEN], int b[LEN], int c[LEN]) {
int i;
for (i = 0; i < LEN; i++)
c[i] = 0;
for (i = LEN - 1; i >= 1; i--) {
c[i] += a[i] + b[i];
if (c[i] >= 10) {
c[i] = c[i] % 10;
c[i - 1] = 1;
}
}
return;
}
void printLDV(int c[LEN]) {
int i, flag = 0;
for (i = 0; i < LEN; i++) {
if (i <= LEN - 81) {
if (c[i] != 0) {
printf("overflow");
flag = 1;
break;
}
} else {
if (c[i] != 0)
flag = 1;
if (flag == 1)
printf("%d", c[i]);
}
}
if (flag == 0)
printf("0");
printf("\n");
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13]]
| 0
| 500
|
#include <math.h>
#include <stdio.h>
#include <string.h>
void rev(char *s) {
int i, d = strlen(s);
char tmp;
for (i = 0; i < d / 2; i++) {
tmp = *(s + i);
*(s + i) = *(s + d - i - 1);
*(s + d - i - 1) = tmp;
}
}
int main() {
int n, p, q, x, y, dt, i, j, k, t, u, flag;
char str1[128], str2[128], msg[256], *v, *w;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str1);
scanf("%s", str2);
rev(str1);
rev(str2);
flag = strlen(str1) > strlen(str2);
t = (!flag) * strlen(str2) + flag * strlen(str1);
u = flag * strlen(str2) + (!flag) * strlen(str1);
v = (flag ? str1 : str2);
w = (flag ? str2 : str1);
strcpy(msg, v);
for (j = 0; j < u; j++) {
for (dt = 0, k = j; k < t; k++) {
x = *(v + k) - '0';
y = abs(((k == j) * (*(w + k) - '0')) % 48);
p = x + y;
q = p % 10;
msg[k] = (q + dt) % 10 + '0';
dt = (p + dt) / 10;
if (k == t - 1 && dt > 0) {
msg[k + 1] = dt + '0';
msg[k + 2] = '\0';
break;
}
if (!dt)
break;
}
strcpy(v, msg);
}
rev(msg);
if (strlen(msg) <= 79) {
for (j = 0; j < strlen(msg); j++)
printf("%d", msg[j] - '0');
printf("\n");
} else {
printf("overflow\n");
}
memset(msg, NULL, sizeof(msg));
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <string.h>
void rev(char *s) {
int i, d = strlen(s);
char tmp;
for (i = 0; i < d / 2; i++) {
tmp = *(s + i);
*(s + i) = *(s + d - i - 1);
*(s + d - i - 1) = tmp;
}
}
int main() {
int n, p, q, x, y, dt, i, j, k, t, u, flag;
char str1[1024], str2[1024], msg[2048], *v, *w;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str1);
scanf("%s", str2);
rev(str1);
rev(str2);
flag = strlen(str1) > strlen(str2);
t = (!flag) * strlen(str2) + flag * strlen(str1);
u = flag * strlen(str2) + (!flag) * strlen(str1);
v = (flag ? str1 : str2);
w = (flag ? str2 : str1);
strcpy(msg, v);
for (j = 0; j < u; j++) {
for (dt = 0, k = j; k < t; k++) {
x = *(v + k) - '0';
y = abs(((k == j) * (*(w + k) - '0')) % 48);
p = x + y;
q = p % 10;
msg[k] = (q + dt) % 10 + '0';
dt = (p + dt) / 10;
if (k == t - 1 && dt > 0) {
msg[k + 1] = dt + '0';
msg[k + 2] = '\0';
break;
}
if (!dt)
break;
}
strcpy(v, msg);
}
rev(msg);
if (strlen(msg) <= 80) {
for (j = 0; j < strlen(msg); j++)
printf("%d", msg[j] - '0');
printf("\n");
} else {
printf("overflow\n");
}
memset(msg, NULL, sizeof(msg));
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
| 0
| 517
|
#include <iostream>
#include <stdio.h>
#include <string.h>
int n;
char a[1000];
int temp[1000], temp2[1000], temp3[1000];
int main() {
std::cin >> n;
while (n--) {
memset(temp, -1, sizeof(temp));
memset(temp2, -1, sizeof(temp2));
memset(temp3, 0, sizeof(temp3));
std::cin >> a;
for (int i = 0; i < strlen(a); i++) {
temp[strlen(a) - i - 1] = a[i] - '0';
}
std::cin >> a;
for (int i = 0; i < strlen(a); i++) {
temp2[strlen(a) - i - 1] = a[i] - '0';
}
int p = 0, f = 0;
while (1) {
if (temp[p] != -1 && temp2[p] != -1) {
temp3[p] = (temp[p] + temp2[p] + f) % 10;
f = (temp[p] + temp2[p] + f) / 10;
} else if (temp[p] != -1) {
temp3[p] = (temp[p] + f) % 10;
f = (temp[p] + f) / 10;
} else if (temp2[p] != -1) {
temp3[p] = (temp2[p] + f) % 10;
f = (temp2[p] + f) / 10;
} else
break;
p++;
}
if (p + f > 79) {
std::cout << "overflow" << std::endl;
continue;
}
if (f)
std::cout << -temp[p];
for (int i = p - 1; i >= 0; i--) {
std::cout << temp3[i];
}
std::cout << std::endl;
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <string.h>
int n;
char a[1000];
int temp[1000], temp2[1000], temp3[1000];
int main() {
std::cin >> n;
while (n--) {
memset(temp, -1, sizeof(temp));
memset(temp2, -1, sizeof(temp2));
memset(temp3, 0, sizeof(temp3));
std::cin >> a;
for (int i = 0; i < strlen(a); i++) {
temp[strlen(a) - i - 1] = a[i] - '0';
}
std::cin >> a;
for (int i = 0; i < strlen(a); i++) {
temp2[strlen(a) - i - 1] = a[i] - '0';
}
int p = 0, f = 0;
while (1) {
if (temp[p] != -1 && temp2[p] != -1) {
temp3[p] = (temp[p] + temp2[p] + f) % 10;
f = (temp[p] + temp2[p] + f) / 10;
} else if (temp[p] != -1) {
temp3[p] = (temp[p] + f) % 10;
f = (temp[p] + f) / 10;
} else if (temp2[p] != -1) {
temp3[p] = (temp2[p] + f) % 10;
f = (temp2[p] + f) / 10;
} else
break;
p++;
}
if (p + f > 80) {
std::cout << "overflow" << std::endl;
continue;
}
if (f)
std::cout << -temp[p];
for (int i = p - 1; i >= 0; i--) {
std::cout << temp3[i];
}
std::cout << std::endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 414
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#define MAX_DIGIT 80
#define ERROR ("Overflow")
int main(void) {
using namespace std;
int N;
cin >> N;
vector<pair<string, string>> input;
input.reserve(N);
for (int i = 1; i <= N; i++) {
string slhs, srhs;
cin >> slhs >> srhs;
reverse(slhs.begin(), slhs.end());
reverse(srhs.begin(), srhs.end());
input.push_back(make_pair(slhs, srhs));
}
for (auto p = input.begin(); p != input.end(); p++) {
auto slhs = p->first, srhs = p->second;
if (slhs.size() > MAX_DIGIT || srhs.size() > MAX_DIGIT) {
cout << ERROR << endl;
continue;
}
int lhs[MAX_DIGIT], rhs[MAX_DIGIT], res[MAX_DIGIT];
fill(lhs, lhs + MAX_DIGIT, 0);
fill(rhs, rhs + MAX_DIGIT, 0);
fill(res, res + MAX_DIGIT, 0);
auto atoi_digit = [](char x) -> int { return atoi(&x); };
transform(slhs.begin(), slhs.end(), lhs, atoi_digit);
transform(srhs.begin(), srhs.end(), rhs, atoi_digit);
int headDigit;
for (headDigit = MAX_DIGIT - 1; headDigit >= 0; headDigit--) {
if (lhs[headDigit] != 0 || rhs[headDigit] != 0) {
break;
}
}
if (headDigit != MAX_DIGIT - 1) {
headDigit++;
}
int carry = 0;
for (int j = 0; j <= headDigit; j++) {
auto d = div(lhs[j] + rhs[j] + carry, 10);
carry = d.quot;
res[j] = d.rem;
}
if (headDigit == MAX_DIGIT - 1 && carry != 0) {
cout << ERROR << endl;
continue;
}
for (; headDigit >= 1; headDigit--) {
if (res[headDigit] != 0) {
break;
}
}
for (int j = headDigit; j >= 0; j--) {
cout << res[j];
}
cout << endl;
}
}
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#define MAX_DIGIT 80
#define ERROR ("overflow")
int main(void) {
using namespace std;
int N;
cin >> N;
vector<pair<string, string>> input;
input.reserve(N);
for (int i = 1; i <= N; i++) {
string slhs, srhs;
cin >> slhs >> srhs;
reverse(slhs.begin(), slhs.end());
reverse(srhs.begin(), srhs.end());
input.push_back(make_pair(slhs, srhs));
}
for (auto p = input.begin(); p != input.end(); p++) {
auto slhs = p->first, srhs = p->second;
if (slhs.size() > MAX_DIGIT || srhs.size() > MAX_DIGIT) {
cout << ERROR << endl;
continue;
}
int lhs[MAX_DIGIT], rhs[MAX_DIGIT], res[MAX_DIGIT];
fill(lhs, lhs + MAX_DIGIT, 0);
fill(rhs, rhs + MAX_DIGIT, 0);
fill(res, res + MAX_DIGIT, 0);
auto atoi_digit = [](char x) -> int { return atoi(&x); };
transform(slhs.begin(), slhs.end(), lhs, atoi_digit);
transform(srhs.begin(), srhs.end(), rhs, atoi_digit);
int headDigit;
for (headDigit = MAX_DIGIT - 1; headDigit >= 0; headDigit--) {
if (lhs[headDigit] != 0 || rhs[headDigit] != 0) {
break;
}
}
if (headDigit != MAX_DIGIT - 1) {
headDigit++;
}
int carry = 0;
for (int j = 0; j <= headDigit; j++) {
auto d = div(lhs[j] + rhs[j] + carry, 10);
carry = d.quot;
res[j] = d.rem;
}
if (headDigit == MAX_DIGIT - 1 && carry != 0) {
cout << ERROR << endl;
continue;
}
for (; headDigit >= 1; headDigit--) {
if (res[headDigit] != 0) {
break;
}
}
for (int j = headDigit; j >= 0; j--) {
cout << res[j];
}
cout << endl;
}
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 1
| 475
|
#include <cstdio>
#include <iostream>
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char moneywrite[2][1000];
int money[2][1000];
int stl[2] = {0, 0};
int stlstl;
int sum[81];
scanf("%s", moneywrite[0]);
scanf("%s", moneywrite[1]);
for (int j = 0; moneywrite[0][j] != '\0'; j++) {
money[0][j] = moneywrite[0][j] - '0';
stl[0]++;
}
for (int j = 0; moneywrite[1][j] != '\0'; j++) {
money[1][j] = moneywrite[1][j] - '0';
stl[1]++;
}
if (stl[0] > stl[1]) {
stlstl = stl[0];
int p;
p = stl[0] - stl[1];
for (int j = 0; j < stl[0]; j++) {
money[1][stl[0] - j] = money[1][stl[0] - j - p];
}
for (int k = 0; k < p; k++)
money[1][k] = 0;
} else if (stl[1] > stl[0]) {
stlstl = stl[1];
int p;
p = stl[1] - stl[0];
for (int j = 0; j < stl[1]; j++) {
money[0][stl[1] - j] = money[0][stl[1] - j - p];
}
for (int k = 0; k < p; k++)
money[0][k] = 0;
} else {
stlstl = stl[1];
}
/*
for(int j=0;j<stlstl;j++)
printf("[%d][%d]\n",money[0][j],money[1][j]);
*/
if (80 <= stlstl) {
printf("overflow");
goto exit;
}
for (int j = stlstl - 1; 0 <= j; j--) {
sum[j] = money[0][j] + money[1][j];
if (10 <= sum[j]) {
if (stlstl == 79 && j == 0) {
printf("overflow");
goto exit;
} else if (j == 0) {
printf("1");
sum[j] %= 10;
} else {
money[0][j - 1]++;
sum[j] %= 10;
}
}
}
for (int j = 0; j < stlstl; j++)
printf("%d", sum[j]);
exit:
puts("");
}
return 0;
}
|
#include <cstdio>
#include <iostream>
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char moneywrite[2][1000];
int money[2][1000];
int stl[2] = {0, 0};
int stlstl;
int sum[81];
scanf("%s", moneywrite[0]);
scanf("%s", moneywrite[1]);
for (int j = 0; moneywrite[0][j] != '\0'; j++) {
money[0][j] = moneywrite[0][j] - '0';
stl[0]++;
}
for (int j = 0; moneywrite[1][j] != '\0'; j++) {
money[1][j] = moneywrite[1][j] - '0';
stl[1]++;
}
if (stl[0] > stl[1]) {
stlstl = stl[0];
int p;
p = stl[0] - stl[1];
for (int j = 0; j < stl[0]; j++) {
money[1][stl[0] - j] = money[1][stl[0] - j - p];
}
for (int k = 0; k < p; k++)
money[1][k] = 0;
} else if (stl[1] > stl[0]) {
stlstl = stl[1];
int p;
p = stl[1] - stl[0];
for (int j = 0; j < stl[1]; j++) {
money[0][stl[1] - j] = money[0][stl[1] - j - p];
}
for (int k = 0; k < p; k++)
money[0][k] = 0;
} else {
stlstl = stl[1];
}
/*
for(int j=0;j<stlstl;j++)
printf("[%d][%d]\n",money[0][j],money[1][j]);
*/
if (81 <= stlstl) {
printf("overflow");
goto exit;
}
for (int j = stlstl - 1; 0 <= j; j--) {
sum[j] = money[0][j] + money[1][j];
if (10 <= sum[j]) {
if (stlstl == 80 && j == 0) {
printf("overflow");
goto exit;
} else if (j == 0) {
printf("1");
sum[j] %= 10;
} else {
money[0][j - 1]++;
sum[j] %= 10;
}
}
}
for (int j = 0; j < stlstl; j++)
printf("%d", sum[j]);
exit:
puts("");
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 13], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
| 1
| 599
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
string s1, s2;
stack<int> sum;
int tmp, carry, n, len1, len2;
cin >> n;
for (int i = 0; i < n; i++) {
tmp = carry = 0;
// clear stack
while (!sum.empty())
sum.pop();
cin >> s1 >> s2;
len1 = s1.length();
len2 = s2.length();
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
for (int i = 0; i < max(len1, len2); i++) {
tmp = carry;
if (i < len1)
tmp += s1[i] - '0';
if (i < len2)
tmp += s2[i] - '0';
sum.push(tmp % 10);
carry = tmp / 10;
}
if (carry != 0) {
sum.push(carry);
carry = 0;
}
if (sum.size() >= 80) {
cout << "overflow" << endl;
} else {
while (!sum.empty()) {
cout << sum.top();
sum.pop();
}
cout << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
string s1, s2;
stack<int> sum;
int tmp, carry, n, len1, len2;
cin >> n;
for (int i = 0; i < n; i++) {
tmp = carry = 0;
while (!sum.empty())
sum.pop();
cin >> s1 >> s2;
len1 = s1.length();
len2 = s2.length();
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
for (int i = 0; i < max(len1, len2); i++) {
tmp = carry;
if (i < len1)
tmp += s1[i] - '0';
if (i < len2)
tmp += s2[i] - '0';
sum.push(tmp % 10);
carry = tmp / 10;
}
if (carry != 0) {
sum.push(carry);
carry = 0;
}
if (sum.size() > 80) {
cout << "overflow" << endl;
} else {
while (!sum.empty()) {
cout << sum.top();
sum.pop();
}
cout << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 283
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <valarray>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int t;
cin >> t;
while (t--) {
string s1, s2;
cin >> s1 >> s2;
if (s1 == "0" && s2 == "0") {
cout << "0" << endl;
continue;
}
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
int n = max(s1.size(), s2.size()) + 1;
for (int i = s1.size(); i < n; i++) {
s1 += '0';
}
for (int i = s2.size(); i < n; i++) {
s2 += '0';
}
string res;
int b = 0;
for (int i = 0; i < max(s1.size(), s2.size()); i++) {
int u = s1[i] - '0' + s2[i] - '0' + b;
b = (u >= 10);
u %= 10;
res += u + '0';
}
reverse(res.begin(), res.end());
string res2;
int j = 0;
while (res[j] == '0')
j++;
for (; j < res.size(); j++) {
res2 += res[j];
}
if (res2.size() >= 80) {
cout << "overflow" << endl;
} else {
cout << res2 << endl;
}
}
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <valarray>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int t;
cin >> t;
while (t--) {
string s1, s2;
cin >> s1 >> s2;
if (s1 == "0" && s2 == "0") {
cout << "0" << endl;
continue;
}
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
int n = max(s1.size(), s2.size()) + 1;
for (int i = s1.size(); i < n; i++) {
s1 += '0';
}
for (int i = s2.size(); i < n; i++) {
s2 += '0';
}
string res;
int b = 0;
for (int i = 0; i < max(s1.size(), s2.size()); i++) {
int u = s1[i] - '0' + s2[i] - '0' + b;
b = (u >= 10);
u %= 10;
res += u + '0';
}
reverse(res.begin(), res.end());
string res2;
int j = 0;
while (res[j] == '0')
j++;
for (; j < res.size(); j++) {
res2 += res[j];
}
if (res2.size() > 80) {
cout << "overflow" << endl;
} else {
cout << res2 << endl;
}
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 369
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
string str1, str2;
int testnum;
cin >> testnum;
int t = 0;
while (t < testnum && cin >> str1 >> str2) {
string sumstr;
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
unsigned size = min(str1.size(), str2.size());
unsigned i;
unsigned carry = 0;
for (i = 0; i < size; ++i) {
unsigned sum = str1[i] + str2[i] + carry - '0' * 2;
sumstr.push_back(sum % 10 + '0');
carry = sum / 10;
}
string large = (str1.size() > str2.size()) ? str1 : str2;
for (; i < large.size(); ++i) {
unsigned sum = large[i] + carry - '0';
sumstr.push_back(sum % 10 + '0');
carry = sum / 10;
}
if (carry)
sumstr.push_back(carry + '0');
reverse(sumstr.begin(), sumstr.end());
if (sumstr.size() <= 81)
cout << sumstr << endl;
else
cout << "overflow" << endl;
t++;
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
string str1, str2;
int testnum;
cin >> testnum;
int t = 0;
while (t < testnum && cin >> str1 >> str2) {
string sumstr;
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
unsigned size = min(str1.size(), str2.size());
unsigned i;
unsigned carry = 0;
for (i = 0; i < size; ++i) {
unsigned sum = str1[i] + str2[i] + carry - '0' * 2;
sumstr.push_back(sum % 10 + '0');
carry = sum / 10;
}
string large = (str1.size() > str2.size()) ? str1 : str2;
for (; i < large.size(); ++i) {
unsigned sum = large[i] + carry - '0';
sumstr.push_back(sum % 10 + '0');
carry = sum / 10;
}
if (carry)
sumstr.push_back(carry + '0');
reverse(sumstr.begin(), sumstr.end());
if (sumstr.size() <= 80)
cout << sumstr << endl;
else
cout << "overflow" << endl;
t++;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 290
|
#include <bits/stdc++.h>
using namespace std;
int f(char x) {
switch (x) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
}
}
int main() {
int n;
for (cin >> n; n--;) {
string a, b;
cin >> a >> b;
if (a.size() > b.size())
swap(a, b);
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
while (a.size() < b.size())
a += '0';
vector<int> c;
c.push_back(0);
for (int i = 0; i < a.size(); i++) {
c[i] += f(a[i]) + f(b[i]);
c.push_back(c[i] / 10);
c[i] %= 10;
}
if (c[c.size() - 1] == 0)
c.pop_back();
reverse(c.begin(), c.end());
if (c.size() >= 80)
cout << "overflow" << endl;
else {
for (int i = 0; i < c.size(); i++)
cout << c[i];
cout << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int f(char x) {
switch (x) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
}
}
int main() {
int n;
for (cin >> n; n--;) {
string a, b;
cin >> a >> b;
if (a.size() > b.size())
swap(a, b);
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
while (a.size() < b.size())
a += '0';
vector<int> c;
c.push_back(0);
for (int i = 0; i < a.size(); i++) {
c[i] += f(a[i]) + f(b[i]);
c.push_back(c[i] / 10);
c[i] %= 10;
}
if (c[c.size() - 1] == 0)
c.pop_back();
// for( int i=c.size()-1 ; c[i]!=0 ; i-- ) c.pop_back() ;
reverse(c.begin(), c.end());
if (c.size() >= 81)
cout << "overflow" << endl;
else {
for (int i = 0; i < c.size(); i++)
cout << c[i];
cout << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 365
|
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
string sum(string &a, string &b) {
int i = a.length() - 1;
int j = b.length() - 1;
int carry = 0;
string temp;
while (i >= 0 || j >= 0) {
int c = i >= 0 ? a[i] - '0' : 0;
int d = j >= 0 ? b[j] - '0' : 0;
temp.push_back((c + d + carry) % 10 + '0');
carry = (c + d) / 10;
--i, --j;
}
if (carry)
temp.push_back('1');
reverse(begin(temp), end(temp));
return temp;
}
int main() {
int n;
cin >> n;
vector<string> input(n * 2);
for (int i = 0; i < n * 2; i++) {
cin >> input[i];
}
for (int i = 0; i < n; i++) {
string t = sum(input[2 * i], input[2 * i + 1]);
if (t.size() <= 80)
cout << t << endl;
else
cout << "overflow" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
string sum(string &a, string &b) {
int i = a.length() - 1;
int j = b.length() - 1;
int carry = 0;
string temp;
while (i >= 0 || j >= 0) {
int c = i >= 0 ? a[i] - '0' : 0;
int d = j >= 0 ? b[j] - '0' : 0;
temp.push_back((c + d + carry) % 10 + '0');
carry = (c + d + carry) / 10;
--i, --j;
}
if (carry)
temp.push_back('1');
reverse(begin(temp), end(temp));
return temp;
}
int main() {
int n;
cin >> n;
vector<string> input(n * 2);
for (int i = 0; i < n * 2; i++) {
cin >> input[i];
}
for (int i = 0; i < n; i++) {
string t = sum(input[2 * i], input[2 * i + 1]);
if (t.length() <= 80)
cout << t << endl;
else
cout << "overflow" << endl;
}
return 0;
}
|
[["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 15, 339, 51, 16, 31, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 119, 120]]
| 1
| 284
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define PI 3.141592653
int main() {
string A, B;
int n, Ak, Bk, ans[81];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 80; j++) {
ans[j] = 0;
}
cin >> A >> B;
if (A == B && A == "0") {
printf("0\n");
continue;
}
Ak = (int)A.size();
Bk = (int)B.size();
if (Ak > 80 || Bk > 80) {
puts("overflow");
continue;
}
for (int j = 0; j < max(Ak, Bk); j++) {
if (j < min(Ak, Bk))
ans[79 - j] += (A[Ak - 1 - j] - '0') + (B[Bk - 1 - j] - '0');
else if (j < Ak)
ans[79 - j] += A[Ak - 1 - j] - '0';
else if (j < Bk)
ans[79 - j] += B[Bk - 1 - j] - '0';
if (ans[79 - j] >= 10) {
if (j == 79) {
break;
}
ans[79 - j - 1]++;
ans[79 - j] -= 10;
}
}
if (ans[79] >= 10) {
puts("overflow");
} else {
bool f = false;
for (int j = 0; j < 80; j++) {
if (ans[j] > 0 || f) {
printf("%1d", ans[j]);
f = true;
}
}
printf("\n");
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define PI 3.141592653
int main() {
string A, B;
int n, Ak, Bk, ans[81];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 80; j++) {
ans[j] = 0;
}
cin >> A >> B;
if (A == B && A == "0") {
printf("0\n");
continue;
}
Ak = (int)A.size();
Bk = (int)B.size();
if (Ak > 80 || Bk > 80) {
puts("overflow");
continue;
}
for (int j = 0; j < max(Ak, Bk); j++) {
if (j < min(Ak, Bk))
ans[79 - j] += (A[Ak - 1 - j] - '0') + (B[Bk - 1 - j] - '0');
else if (j < Ak)
ans[79 - j] += A[Ak - 1 - j] - '0';
else if (j < Bk)
ans[79 - j] += B[Bk - 1 - j] - '0';
if (ans[79 - j] >= 10) {
if (j == 79) {
break;
}
ans[79 - j - 1]++;
ans[79 - j] -= 10;
}
}
if (ans[0] >= 10) {
puts("overflow");
} else {
bool f = false;
for (int j = 0; j < 80; j++) {
if (ans[j] > 0 || f) {
printf("%1d", ans[j]);
f = true;
}
}
printf("\n");
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13]]
| 1
| 421
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string a, b, c, d;
cin >> a;
cin >> b;
int x = max(a.length(), b.length());
for (int j = 0; j < x - a.length() + 1; j++) {
c += "0";
}
for (int j = 0; j < x - b.length() + 1; j++) {
d += "0";
}
c += a;
d += b;
for (int j = 0; j < x + 1; j++) {
c[j] += d[j] - '0';
}
for (int j = x; j >= 0; j--) {
if (c[j] > '9') {
c[j] -= 10;
c[j - 1]++;
}
}
if (c[0] != '0') {
if (x >= 79) {
cout << "overflow" << endl;
continue;
}
cout << c[0];
} else {
if (x >= 80) {
cout << "overflow" << endl;
continue;
}
}
for (int j = 1; j <= x; j++) {
cout << c[j];
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string a, b, c, d;
cin >> a;
cin >> b;
int x = max(a.length(), b.length());
for (int j = 0; j < x - a.length() + 1; j++) {
c += "0";
}
for (int j = 0; j < x - b.length() + 1; j++) {
d += "0";
}
c += a;
d += b;
for (int j = 0; j < x + 1; j++) {
c[j] += d[j] - '0';
}
for (int j = x; j >= 0; j--) {
if (c[j] > '9') {
c[j] -= 10;
c[j - 1]++;
}
}
if (c[0] != '0') {
if (x >= 80) {
cout << "overflow" << endl;
continue;
}
cout << c[0];
} else {
if (x >= 81) {
cout << "overflow" << endl;
continue;
}
}
for (int j = 1; j <= x; j++) {
cout << c[j];
}
cout << endl;
}
}
|
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 300
|
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, c = 0, tmp;
cin >> N;
string ans;
for (int i = 0; i < N; i++) {
ans = "";
string a, b;
cin >> a >> b;
for (int j = 0; j < max(a.length(), b.length()); j++) {
int A, B;
A = a.length() - j - 1;
B = b.length() - j - 1;
tmp = (A >= 0 ? a[A] - '0' : 0) + (B >= 0 ? b[B] - '0' : 0) + c;
ans = (char)(tmp % 10 + '0') + ans;
c = tmp / 10;
}
if (c) {
ans = '1' + ans;
}
cout << (ans.length() > 80 ? "overflow" : ans) << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, c, tmp;
cin >> N;
string ans;
for (int i = 0; i < N; i++) {
ans = "";
c = 0;
string a, b;
cin >> a >> b;
for (int j = 0; j < max(a.length(), b.length()); j++) {
int A, B;
A = a.length() - j - 1;
B = b.length() - j - 1;
tmp = (A >= 0 ? a[A] - '0' : 0) + (B >= 0 ? b[B] - '0' : 0) + c;
ans = (char)(tmp % 10 + '0') + ans;
c = tmp / 10;
}
if (c) {
ans = '1' + ans;
}
cout << (ans.length() > 80 ? "overflow" : ans) << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 220
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, i, j;
cin >> n;
for (i = 0; i < n; i++) {
string str1, str2, temp;
int kuriagari = 0;
cin >> str1 >> str2;
if (str1.size() < str2.size()) {
temp = str1;
str1 = str2;
str2 = temp;
}
int goukei[str1.size() + 1];
for (j = 0; j < str1.size() + 1; j++) {
if (j == str1.size()) {
goukei[0] = kuriagari;
} else if (j < str2.size()) {
goukei[str1.size() - j] = str2[str2.size() - 1 - j] +
str1[str1.size() - 1 - j] + kuriagari - '0' -
'0';
if (goukei[str1.size() - j] >= 10) {
goukei[str1.size() - j] -= 10;
kuriagari = 1;
} else {
kuriagari = 0;
}
} else {
goukei[str1.size() - j] = str1[str1.size() - 1 - j] + kuriagari - '0';
if (goukei[str1.size() - j] >= 10) {
goukei[str1.size() - j] -= 10;
kuriagari = 1;
} else {
kuriagari = 0;
}
}
}
if ((str1.size() > 81) || ((str1.size() == 80) && (goukei[0] == 1))) {
cout << "overflow" << endl;
} else {
if (goukei[0] != 0)
cout << goukei[0];
for (j = 0; j < str1.size(); j++)
cout << goukei[j + 1];
cout << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, i, j;
cin >> n;
for (i = 0; i < n; i++) {
string str1, str2, temp;
int kuriagari = 0;
cin >> str1 >> str2;
if (str1.size() < str2.size()) {
temp = str1;
str1 = str2;
str2 = temp;
}
int goukei[str1.size() + 1];
for (j = 0; j < str1.size() + 1; j++) {
if (j == str1.size()) {
goukei[0] = kuriagari;
} else if (j < str2.size()) {
goukei[str1.size() - j] = str2[str2.size() - 1 - j] +
str1[str1.size() - 1 - j] + kuriagari - '0' -
'0';
if (goukei[str1.size() - j] >= 10) {
goukei[str1.size() - j] -= 10;
kuriagari = 1;
} else {
kuriagari = 0;
}
} else {
goukei[str1.size() - j] = str1[str1.size() - 1 - j] + kuriagari - '0';
if (goukei[str1.size() - j] >= 10) {
goukei[str1.size() - j] -= 10;
kuriagari = 1;
} else {
kuriagari = 0;
}
}
}
if ((str1.size() >= 81) || ((str1.size() == 80) && (goukei[0] == 1))) {
cout << "overflow" << endl;
} else {
if (goukei[0] != 0)
cout << goukei[0];
for (j = 0; j < str1.size(); j++)
cout << goukei[j + 1];
cout << endl;
}
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 23, 0, 16, 17, 47], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 17, 20]]
| 1
| 408
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.