2010-02-01から1ヶ月間の記事一覧

Problem21

#include <iostream> #include <vector> #include <set> #include <cmath> using namespace std; #define NUM 10000 void aliquot(int n, set<int> *pset_pf) { pset_pf->insert(1); if(n == 2) { return; } bool *t = new bool [n]; memset(t, false, n); t[1] = true; for (int i = 2; i < n; </int></cmath></set></vector></iostream>…

Problem20

#include <iostream> #include <string> using namespace std; #define NUM 100 void multi(string *ps, int num) { string s(""); int c = 0; for (string::size_type i = ps->size(); i > 0; i--) { int n = (ps->at(i-1)-'0') * num + c; c = n/10; s += '0' + n%10; } if (</string></iostream>…

Problem19

#include <iostream> using namespace std; #define START 1901 #define END 2000 bool isLeap(int y) { if (y%4 != 0 || (y%100 == 0 && y%400 != 0)) { return false; } else { return true; } } int main(int argc, char **argv) { int md[13] = { 0, 31, 28, 31, 3</iostream>…

Problem18

#include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; #define NUM "\ 75\n\ 95 64\n\ 17 47 82\n\ 18 35 87 10\n\ 20 04 82 47 65\n\ 19 01 23 75 03 34\n\ 88 02 77 73 07 63 67\n\ 99 65 04 28 06 16 70 92\n\ 41 41 26 56 83 40 80 70 33\n\ 4</vector></string></sstream></iostream>…

Problem17

#include <iostream> #include <string> using namespace std; #define NUM 1000 string numlen(int n) { if (n == 1000) { return "onethousand"; } string s; char fig1[10][7] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; char</string></iostream>…

Problem16

#include <iostream> #include <string> using namespace std; #define NUM 1000 void multi(string *ps, int num) { string s(""); int c = 0; for (string::size_type i = ps->size(); i > 0; i--) { int n = (ps->at(i-1)-'0') * num + c; c = n/10; s += '0' + n%10; } if </string></iostream>…

Problem15

#include <iostream> #include <cmath> using namespace std; #define NUM 20 double fctr(int n) { double r = 1; for (int i = 2; i <= n; i++) { r *= i; } return r; } int main(int argc, char argv) { double ans; ans = fctr(NUM*2) / (fctr(NUM)*fctr(NUM)); printf("</cmath></iostream>…

Problem14

#include <iostream> using namespace std; #define NUM 1000000 int main(int argc, char **argv) { bool t[NUM]; memset(t, true, NUM); int ans = -1; int max = -1; for (int i = 2; i < NUM; i++) { if (t[i] == false) { continue; } unsigned int n = i; int l </iostream>…

Problem13

#include <iostream> #include <string> #include <vector> using namespace std; /* #define NUM "\ 37107287533902102798797998220837590246510135740250\ 46376937677490009712648124896970078050417018260538\ 74324986199524741059474233309513058123726617309629\ " */ #define N</vector></string></iostream>…

Problem 12

#include <iostream> #include <vector> #include <cmath> using namespace std; #define NUM 501 #define DST 100 void primeVector(vector<bool> *pv_table) { pv_table->at(0) = pv_table->at(1) = false; for (vector<bool>::size_type i = 2, end = (vector<bool>::size_type)ceil(sqrt((double)(pv</bool></bool></bool></cmath></vector></iostream>…

Problem 11

#include <iostream> #include <sstream> using namespace std; #define CLM 20 #define ROW 20 #define MAT "\ 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 \ 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 \ 81 49 31 73 55 79 14 29 93 71</sstream></iostream>…

Problem 10

#include <iostream> #include <vector> #include <cmath> using namespace std; #define NUM 2000000 #define DST 100000 void primeVector(vector<bool> *pv_table) { pv_table->at(0) = pv_table->at(1) = false; for (vector<bool>::size_type i = 2, end = (vector<bool>::size_type)ceil(sqrt((dou</bool></bool></bool></cmath></vector></iostream>…

Problem 9

#include <iostream> #include <cmath> using namespace std; #define SUM 1000 int main(int argc, char **argv) { int ans = -1; bool f = false; for (int a = 1; a < SUM; a++) { for (int b = a+1; b < SUM; b++) { int c = SUM - (a+b); if (a > b || b > c) { break; }</cmath></iostream>…

Problem 8

#include <iostream> #include <string> using namespace std; #define NUM "\ 73167176531330624919225119674426574742355349194934\ 96983520312774506326239578318016984801869478851843\ 85861560789112949495459501737958331952853208805511\ 125406987471585238630507156</string></iostream>…

Problem 7

#include <iostream> #include <vector> #include <cmath> using namespace std; #define NUM 10001 #define DST 100 void primeVector(vector<bool> *pv_table) { pv_table->at(0) = pv_table->at(1) = false; for (vector<bool>::size_type i = 2, end = (vector<bool>::size_type)ceil(sqrt((double)(</bool></bool></bool></cmath></vector></iostream>…

Problem 6

#include <iostream> #include <cmath> using namespace std; #define NUM 100 int main(int argc, char **argv) { double sp; // 和の二乗 double ps; // 二乗数の和 // 和の二乗 sp = 0; for (int i = 1; i <= NUM; i++) { sp += i; } sp = pow(sp, 2.0); // 二乗数の和 ps </cmath></iostream>…

Problem 5

#include <iostream> #include <vector> #include <cmath> using namespace std; #define NUM 20 // 素数テーブルの作成 void primeTable(int l, bool t_prime[]) { unsigned int size = (unsigned int)ceil(sqrt((double)NUM)); // 篩の大きさ memset(t_prime, true, NUM); // 篩にか</cmath></vector></iostream>…

Problem 4

斜めに総当たり戦する感じです. #include <iostream> #include <cmath> using namespace std; #define MAX 999 bool isPalindrome(int n) { bool f = false; if (100000 <= n && n <= 999999) { char l[4], r[4]; // 下3桁を反転 for (int i = 0; i < 3; i++) { r[i] = '0' +</cmath></iostream>…

Problem 3

篩も懐かしいねー #include <iostream> #include <cmath> using namespace std; #define NUM 600851475143 int main(int argc, char ** argv) { unsigned int size = (unsigned int)ceil(sqrt((double)NUM)); // 篩の大きさ bool *t_prime = new bool [size]; // 素数テーブル</cmath></iostream>…

Problem 2

フィボナッチさん懐かしいねー #include <iostream> #include <vector> using namespace std; #define LIMIT 4000000 int main(int argc, char **argv) { vector<int> vf; // フィボナッチ数列 vf.push_back(1); vf.push_back(2); while (1) { vector<int>::size_type e = vf.size(); vf.</int></int></vector></iostream>…

Problem 1

set を使っているのは単に使ってみたかっただけです. #include <iostream> #include <set> using namespace std; #define NUM 1000 int main(int argc, char **argv) { set<int> s; for (int i = 3; i < NUM; i+=3) { s.insert(i); } for (int i = 5; i < NUM; i+=5) { s.insert</int></set></iostream>…