赞
踩
用于记录完成noj时遇到的问题和对自己来说需要注意的事项,可供参考,不建议抄袭。
- #include<iostream>
- using namespace std;
-
- int main()
- {
- cout << "Hello World";
- }
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int a, b;
- cin >> a >> b;
- cout << a + b;
- }
-
-
- #include<iostream>
- #include<stdio.h>
- #include<limits.h>
- using namespace std;
-
- int main()
- {
- int d;
- cin >> d;
-
- switch (d)
- {
- case 1:
- cout << sizeof(char) << ',' << CHAR_MIN << ',' << CHAR_MAX;
- break;
- case 2:
- cout << sizeof( unsigned char) << ',' << 0 << ',' << UCHAR_MAX;
- break;
- case 3:
- cout << sizeof(short) << ',' << SHRT_MIN << ',' << SHRT_MAX;
- break;
- case 4:
- cout << sizeof(unsigned short) << ',' << 0 << ',' << USHRT_MAX;
- break;
- case 5:
- cout << sizeof(int) << ',' << INT_MIN << ',' << INT_MAX;
- break;
- case 6:
- cout << sizeof(unsigned int) << ',' << 0 << ',' << UINT_MAX;
- break;
- case 7:
- cout << sizeof(long) << ',' << LONG_MIN << ',' << LONG_MAX;
- break;
- case 8:
- cout << sizeof(unsigned long) << ',' << 0 << ',' << ULONG_MAX;
- break;
- case 9:
- cout << sizeof(long long) << ',' << LLONG_MIN << ',' << LLONG_MAX;
- break;
- case 10:
- cout << sizeof(unsigned long long) << ',' << 0 << ',' << ULLONG_MAX;
- break;
- default:;
- }
-
- }
-
-
-
使用XXX_MAX/MIN要记得用<limits.h>库
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int a, b;
- cin >> a >> b;
- cout << a + ((b - a) >>1);
-
- }
注意不能直接使用(a+b)/2,会造成数据溢出
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int a;
- cin >> a;
-
- cout << uppercase << hex << a << "," << oct << a;
-
- }
- #include<iostream>
- #include<stdio.h>
- using namespace std;
-
- int main()
- {
- double a;
- cin >> a;
- printf("%.6f,%.2f,%.8f", a, a, a);
- }
- #include<iostream>
- #include<iomanip>
- using namespace std;
-
- int main()
- {
- int a, b;
- cin >> a >> b;
- cout << setw(b)<<setfill('0') << a;
- }
引用<iomanip>库后,可以使用setw(int n)设置域宽为n,使用setfill(char c)填充字符
- #include<iostream>
- #include<math.h>
- using namespace std;
-
- double lon1, lat1, lon2, lat2;
- const double r = 6371.0, pi = 3.1415926535;
-
- double hav(double x)
- {
- return (1 - cos(x)) / 2;
- }
-
- double rad(double *x)
- {
- return *x = *x * pi / 180;
- }
-
- int main()
- {
- double h,d;
- cin >> lat1 >> lon1 >>lat2 >> lon2;
-
- rad(&lat1); rad(&lon1); rad(&lat2); rad(&lon2);
- h = hav(lat2 - lat1) + cos(lat1) * cos(lat2) * hav(lon2 - lon1);
- d = acos(1 - (2 * h)) * r;
-
- printf("%.4fkm", d);
-
- return 0;
- }
-
注意看题别把经纬度搞错了,变量和意义要对应上。
- #include<iostream>
- #include<cmath>
- using namespace std;
-
- int main()
- {
- double v, t, c,v1;
-
- cin >> v >> t;
- v1 = pow(v, 0.16);
- c = 13.12 + 0.6215 * t - (11.37 * v1) + (0.3965 * t * v1);
- printf("%.0f", c);
- }
引用<cmath>后可以使用pow(x,y)函数进行指数运算,结果为x的y次方
格式输出可以把浮点型转换为整型输出并四舍五入
- #include<stdio.h>
- #include<math.h>
- #include<stdlib.h>
- int max(int R, int G, int B)
- {
- if (R >= G && R >= B) return R;
- if (G >= R && G >= B) return G;
- if (B >= R && B >= G) return B;
- }
- int min(int R, int G, int B)
- {
- if (R <= G && R <= B) return R;
- if (G <= R && G <= B) return G;
- if (B <= R && B <= G) return B;
- }
- int main()
- {
- int R, G, B;
- double V, S, H, n;
- scanf("%d%d%d", &R, &G, &B);
- V = max(R, G, B);
- n = min(R, G, B);
- S = (V - n) / V;
- if (V == R)
- H = 60 * (G - B) / (V - n);
- if (V == G)
- H = 120 + 60 * (B - R) / (V - n);
- if (V == B)
- H = 240 + 60*(R - G) / (V - n);
- if (V == 0)
- S=0;
- if (H < 0)
- H = H + 360;
- printf("%.4lf,%.4lf%%,%.4lf%% ", H, S * 100, V * 100 / 255);
- return 0;
- }
评论区提供的
- #include<stdio.h>
- using namespace std;
-
- int a_up, a_down, b_up, b_down;
- int c_up, c_down;
- //分数化简
- void simplify(int* up, int* down)
- {
-
- //化简
- int i;
- if (*up > 0)
- {
- for (i = *up; i >= 1; i--)
- {
- if ((*up % i == 0) && (*down % i == 0))
- {
- *up = *up / i;
- *down = *down / i;
- }
- }
- }
- if (*up < 0)
- {
- for (i = *up; i <=- 1; i++)
- {
- if ((*up % i == 0) && (*down % i == 0))
- {
- *up = *up / i;
- *down = *down / i;
- }
- }
- }
- //使分母恒正,分子决定分数负
- if (*down < 0)
- {
- *up = -*up;
- *down = -*down;
- }
- }
- //输出结果
- void output(char c)
- {
- if (c_down == 0)
- printf("error\n");
- else if (c_down==1)
- printf("(%d/%d)%c(%d/%d)=%d\n", a_up, a_down, c, b_up, b_down, c_up);
- else if(c_up==0)
- printf("(%d/%d)%c(%d/%d)=0\n", a_up, a_down, c, b_up, b_down);
- else
- printf("(%d/%d)%c(%d/%d)=%d/%d\n", a_up, a_down, c, b_up, b_down, c_up, c_down);
- }
-
- int main()
- {
- //输入分数并化简
- scanf("%d/%d", &a_up, &a_down);
- scanf("%d/%d", &b_up, &b_down);
- simplify(&a_up, &a_down);
- simplify(&b_up, &b_down);
- //加法运算并化简输出
- c_up = a_up * b_down + a_down * b_up;
- c_down = a_down * b_down;
- simplify(&c_up, &c_down);
- output('+');
- //减法运算并化简输出
- c_up = a_up * b_down - a_down * b_up;
- c_down = a_down * b_down;
- simplify(&c_up, &c_down);
- output('-');
- //乘法运算并化简输出
- c_up = a_up * b_up;
- c_down = a_down * b_down;
- simplify(&c_up, &c_down);
- output('*');
- //除法运算并化简输出
- c_up = a_up * b_down;
- c_down = a_down * b_up;
- simplify(&c_up, &c_down);
- output('/');
- }
注意审题,输入的数字再输出时要带括号,计算结果不带
注意考虑结果中的整数和等于0的情况
通过for循环时注意正负数寻找最大公因数方式不同,可以分情况或用绝对值解决
定义新函数可以使代码简洁一点
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int line,i,t,sum;
- int n[100000];
- cin >> line;
-
- for (i = 1; i <= line; i++)cin >> n[i];
- for (i = 1; i <= line; i++)
- {
- sum = 0;
- for (t = 3; t <n[i]; t=t+3)
- sum = sum + t;
- for (t = 5; t < n[i]; t =t+5)
- sum = sum + t;
- for (t = 15; t < n[i]; t=t+15)
- sum = sum - t;
- cout << sum << endl;
- }
- return 0;
- }
动态数组没弄明白,数组直接上取值范围个吧
- #include<iostream>
- using namespace std;
-
- int main()
- {
- long long a, b, m;
- long long ans = 1;
- cin >> a >> b >> m;
- while (b)
- {
- if (b & 1ull)ans = ans* a % m;
- b >>= 1ull;
- a = a * a % m;
- }
- cout << ans;
- }
递推快速幂
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int n, i;
- int integer = 1, dec = 2,t=10;
- double result=0;
- cin >> n;
-
- for (i = 1; i <= n; i++)
- {
- if (i == 9)
- t *= 10;
- if (i == 99)
- t *= 10;
- result = result+ (double)integer + (double)dec / t;
- switch (dec)
- {
- case 10:
- cout << integer << '.' << dec / 10;
- break;
- case 100:
- cout << integer << '.' << dec / 100;
- break;
- default:
- cout << integer << '.' << dec;
- }
- if(i<n)
- cout << '+';
- else
- cout << '=' << result;
- integer++;
- dec++;
- }
- return 0;
- }
小数点后无意义的0记得去掉
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int a, b, c, d, n, t=0;
- cin >> n;
- for (a=0;a<=9;a++)
- {
- for (b = 0; b<=9; b++)
- {
- for (c = 0; c<=9; c++)
- {
- for (d = 0; d<=9; d++)
- {
- if ((a + b + c + d) == n)
- t++;
- }
- }
- }
- }
- cout << t;
- }
穷举即可
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int row, col, i,n;
- cin >> n;
-
- for (row = 1; row <= n; row++)
- {
- i = row - 1;
- for (col = 1; col<= n; col++)
- {
- cout << i;
- if (col == n)
- cout << endl;
- else
- cout << ' ';
- if ((row - col) > 0)
- i--;
- if ((row - col) <= 0)
- i++;
-
- }
- }
- }
- #include<iostream>
- using namespace std;
-
- int main()
- {
- long long a, b, m, result;
- cin >> a >> b >> m;
-
- result = ((a % m) * (b % m)) % m;
- cout << result;
-
- }
直接运算会导致数据溢出,可以根据(a*b)%m=(a%m)*(b%m)%m运算
- #include<iostream>
- #include<cmath>
- using namespace std;
- #define PRECISION 0.000001
-
- void simplify(int* up, int* down)//化简分数
- {
-
- //化简
- int i;
- if (*up > 0)
- {
- for (i = *up; i >= 1; i--)
- {
- if ((*up % i == 0) && (*down % i == 0))
- {
- *up = *up / i;
- *down = *down / i;
- }
- }
- }
- if (*up < 0)
- {
- for (i = *up; i <= -1; i++)
- {
- if ((*up % i == 0) && (*down % i == 0))
- {
- *up = *up / i;
- *down = *down / i;
- }
- }
- }
- //使分母恒正,分子决定分数负
- if (*down < 0)
- {
- *up = -*up;
- *down = -*down;
- }
- }
-
- int main()
- {
- double n;
- int up, down;
- int tens;//用于计算小数部分位数
- cin >> n;
-
- double decimal = n - (int)n;//获取小数部分
- for (tens=1; abs(round(decimal) - decimal) > PRECISION; tens *= 10)
- decimal *= 10;
- up = n * tens;
- down = tens;//把小数乘10的小数位数次并除以十的小数位数次,转化为分数
- simplify(&up, &down);// 化简
-
- cout << up << "/" << down;
-
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- //计算位数
- int wide(int a)
- {
- int i;
- for (i=0;a!=0;i++)
- {
- a = a /10;
- }
- return i;
- }
-
- //进行一次减去各位数字和的操作
- int operate(int a)
- {
- int times, i, add, res;
-
- res = a;
- times = wide(a);
- for (i = 1; i <= times; i++)
- {
- add = a % 10;
- a = a / 10;
- res = res - add;//每次循环减去一位数字的值
- }
- return res;
- }
- int main()
- {
- int n, i, add,res;
- cin >> n;
- res = n;
- //计录操作次数
- for (i = 0; res >0;i++)
- {
- res = operate(res);
- }
- cout << i;
-
- return 0;
- }
这个写法复杂了,其实可以两个for循环解决的
-
- #include<iostream>
- #include<cmath>
- using namespace std;
-
- int wide(int a)
- {
- int i;
- for (i = 0; a != 0; i++)
- {
- a = a / 10;
- }
- return i;
- }
-
-
- int main()
- {
- int n, times,i,res;
- cin >> n;
- times = wide(n)/2;
- res = 1;
-
- for (i = 1; i <= times; i++)
- {
- int left =( n / (int)pow(10.0, wide(n)-i))%10;
- int right = (n % (int)pow(10.0, i)) / (int)pow(10.0, i-1);
- if (left == 1 && right == 1 || left == 9 && right == 6 || left == 6 && right == 9 || left == 8 && right == 8)
- res = res;
- else
- res = 0;
- }
-
- if (res == 1)
- cout << "Yes";
-
- else
- cout<<"No";
- }
-
-
Yes和No别忘了大写
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int N, result, left, right,tens,wrong;
- cin >> N;
-
- if (N < 10)cout << N;
- else left = N / 10 % 10;
- for (result = N; result >= 10; result--)
- {
-
- for (tens = 10,wrong=0; wrong==0&&result/tens>0; tens *= 10)
- {
- left = result / tens % 10;
- right = (result * 10 / tens) % 10;
- if (left > right)
- wrong ++;
- }
- if (right == 0) wrong++;
- if (wrong == 0)
- {
- cout << result;
- break;
- }
- }
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int n, k, sum=0;
- cin >> n >> k;
-
- int i;
- for (i = 1; i <= n; i++)
- {
- sum += k % i;
- }
- cout << sum;
- }
- #include<iostream>
- #include<iomanip>
- using namespace std;
-
- int widenum(int a)
- {
- int i;
- for (i = 0; a != 0; i++)
- {
- a = a / 10;
- }
- return i;
- }
- int ten(int a)
- {
- int i,ten=1;
- for (i = 1; i <= a; i++)
- ten *= 10;
- return ten;
- }
-
- int main()
- {
- int n1, n2, wide;
- int i;
- cin >> n1 >> n2;
- wide = widenum(n1 * n2);
-
- cout << setw(wide+1) << right << n1 << endl;
- cout << 'x' << setw(wide) << right << n2 << endl;
- for (i = 0; i <= wide; i++)
- cout << '-';
- cout << endl;
- for (i = 0; i < widenum(n2)-1; i++)
- cout << setw(wide+1 - i) << right << (n2 / ten(i) % 10) * n1 << endl;
- cout<<'+'<<setw(wide - i) << right << (n2 / ten(i) % 10) * n1 << endl;
- for (i = 0; i <= wide; i++)
- cout << '-';
- cout << endl;
- cout <<setw(wide+1)<<right<< n1 * n2;
-
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
-
- int Pour(int m, int n, int d)
- {
- int mreal= 0, nreal= 0, step1 = 0, step2 = 0;
- while (mreal != d && nreal != d) {
- if (mreal == 0) {
- mreal = m;
-
- }
- else if (nreal == n) {
- nreal = 0;
-
- }
- else {
- int total = nreal + mreal > n ? n - nreal : mreal;
- mreal -= total;
- nreal += total;
-
- }
- step1++;
- }
-
- mreal = 0, nreal = 0;
- while (mreal != d && nreal != d) {
- if (nreal == 0) {
- nreal = n;
-
- }
- else if (mreal == m) {
- mreal = 0;
-
- }
- else {
- int total = mreal + nreal > m ? m - mreal : nreal;
- nreal -= total;
- mreal += total;
- }
- step2++;
- }
- int step = step1 > step2 ? step2 : step1;
- return step;
- }
- int main() {
- int m, n, d;
- cin >> m >> n >> d;
- cout << Pour(m, n, d);
-
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- int main() {
- int n;
- cin >> n;
- for (int a = 1; a < n; a++) {
- for (int b = a; b < n; b++) {
- int c = n - a - b;
- if (a * a + b * b == c * c) {
- cout << a * b * c << endl;
- return 0;
- }
- }
- }
- cout << "No solution" << endl;
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int n1, n2,res=0;
- cin >> n1 >> n2;
-
- while (n1 != 0)
- {
- if (n1 % 2 != 0)res += n2;
- cout << n1 << ' ' << n2 << endl;
- n1 >>=1;
- n2 <<=1;
- }
- cout << res;
-
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- int main()
- {
- int i,j, a,n;
- cin >> n;
-
- for (i = 1, a = 1; a<n; i++)
- {
- for (j = 1; j <= i; j++, a++)
- if (a == n)break;
- }
- cout << j;
-
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- int iter(int n,int i)
- {
- int tmp=0;
- while (i > 0)
- {
- tmp += i;
- i--;
- if (tmp == n)return 1;
- else if(tmp > n)break;
- }
- return 0;
- }
-
- int solution(int n)
- {
- int i, res=1;
- for (i = (n / 2) + 1; i >= 2; i--)
- res += iter(n, i);
- return res;
- }
-
- int main()
- {
- int n;
- cin >> n;
-
- switch (n)
- {
- case 1:
- case 2:
- cout << '1';
- break;
- default:
- cout << solution(n);
- }
-
- return 0;
- }
- #include<iostream>
- #include<cmath>
- using namespace std;
-
- long goodNumber(long N, long i) {
- if (i == N) return 1;
- else if ((i % 2) == 0) {
- return (5 * goodNumber(N, i + 1)) % ((int)pow(10, 9) + 7);
- }
- else if ((i % 2) == 1) {
- return (4 * goodNumber(N, i + 1)) % ((int)pow(10, 9) + 7);
- }
- }
- int main()
- {
- long N, i = 0;
- cin >> N;
-
- cout << goodNumber(N, i);
-
- return 0;
- }
- #include<iostream>
- #include <initializer_list>//用来实现可变参数
- //关于可变参数的实现可以参考https://blog.csdn.net/qq_32534441/article/details/103495144?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169871084216777224498801%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=169871084216777224498801&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-103495144-null-null.142^v96^pc_search_result_base6&utm_term=%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0&spm=1018.2226.3001.4187
- // 此处选择 initializer_list标准库类型
- //1.initializer_list在C++11中才被引入,这意味着在编译时可能需要加上这个选项 - std = c++11 才能成功编译。上述代码中的auto关键字也是C++11的一部分;
- //2. 参数必须放在一组‘{}’(大括号)内,编译器通过大括号来将这组参数转化为initializer_list.大括号的的一组实参与initializer_list形参对应;
- //3. 函数原型initializer_list与普通形参无异。这表明形参列表中可以包含其他类型参数且位置不限
- using namespace std;
-
- int sum(initializer_list<int> il)//函数原型用int实例化initializer_list作为形参
- {
- int sum = 0;
- for (auto p = il.begin(); p != il.end(); p++) //使用迭代器访问参数
- sum += *p;
- return sum;
-
- }
-
- int main()
- {
- int a, b, c, d, e, f;
- cin >> a >> b >> c >> d >> e >> f;
-
- cout << sum({ a,b,0 }) - sum({ c,d,e,f,0 });//想向initializer_list形参中传递一个值的序列,必须把序列放在一对花括号内
-
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- int HarshadNumber(int n){
- int t=n,s=0;
- while(t){
- s=s+t%10;
- t=t/10;
- }
- if(s!=0 && n%s==0) return n/s;
- return 0;
- }
- int main(){
- int n,i=0;
- cin >> n;
-
- while(n>=2){
- if(HarshadNumber(n)!=0){
- n = HarshadNumber(n);
- i++;
- }
- else break;
- }
- cout << i << endl;
- return 0;
- }
- #include<iostream>
- using namespace std;
-
- double pow(double base,int exp=2)
- {
- double res=1;
- for (int i = 1; i <= exp; i++)
- {
- res*=base;
- }
- return res;
- }
-
- int main()
- {
- double base;
- int exp;
- cin >> base >> exp;
-
- printf("%.6f\n", pow(base));
- printf("%.6f", pow(base, exp));
-
- return 0;
- }
- #include<iostream>
- #include<cmath>
- using namespace std;
-
- int judge(int n)
- {
- int i;
- for (i = 2; i < 6; i++)
- if (n % i == 0)return 0;
- for (i = 1; 6 * i + 5 <n/i; i++)
- if (n % (6 * i + 1) == 0 || n % (6 * i + 5) == 0)return 0;
- return 1;
- }
-
- int main()
- {
- int left, right, res=0;
- cin >> left >> right;
- for (int i = left; i <= right; i++)
- if (judge(i)==1)res++;
- cout << res;
- }
- #include <iostream>
- using namespace std;
- int main() {
- long long n , x;
- cin >> n >> x;
- if (n % 2 == 1){
- cout << (n - 1) * 3 << endl;
- }
- else{
- cout << 3 * ((n / 2) + abs(x - (n / 2))) << endl;
- }
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
-
- inline bool IsKeith(int n){
- int tmp=n,nums_i=99,lens=0;
- int nums[200]={0};
- while(tmp>0){
- nums[nums_i]=tmp%10;
- tmp/=10;
- nums_i++;
- }
- lens=nums_i-99;
- while(nums[nums_i-lens-1]!=n){
- for(int i=nums_i-1;i>=nums_i-lens;i--){
- nums[nums_i-lens-1]+=nums[i];
- }
- if(nums[nums_i-lens-1]==n) return true;
- else if(nums[nums_i-lens-1]>n||(nums_i-lens-1)<0) break;
- nums_i--;
- }
- return false;
- }
- int main() {
- int n;
- std::cin >> n;
- if(IsKeith(n)) std::cout<<"Yes"<<std::endl;
- else std::cout << "No"<<std::endl;
- return 0;
- }
- #include<iostream>
- #include<stdarg.h>
- using namespace std;
-
- double avg(int n,...)
- {
- int i, val;
- double sum=0;
- va_list v1;
- va_start(v1, n);
- for (i = 0; i < n; i++)
- {
- val = va_arg(v1, double);
- sum += val;
- }
- va_end(v1);
- return sum / i;
- }
-
-
- int main()
- {
- double a, b, c, d, e;
- cin >> a >> b >> c >> d >> e;
- printf("%.4f", avg(2, a, b) - avg(3, c, d, e));
- }
- #include<iostream>
- using namespace std;
-
- int PA(int n)
- {
- if (n==0)return 0;
- else if (n == 1)return 1;
- return 2 * PA(n - 1) + PA(n - 2);
- }
-
- int PB(int n)
- {
- int p0 = 0, p1 = 1, pn, i;
- for (i = 0; i <= n; i++)
- {
- if (i == 0)pn = p0;
- else if (i == 1)pn = p1;
- else
- {
- pn = 2 * p1 + p0;
- p0 = p1;
- p1 = pn;
- }
- }
- return pn;
- }
-
-
- int main()
- {
- int n;
- cin >> n;
-
- if (n % 2 != 0)cout << PA(n);
- else cout << PB(n);
-
- return 0;
- }
- #include<bits/stdc++.h>
- using namespace std;
- const int N = 50000;
- int vis[N];
- int prime[N];
- int phi[N];
- int sum[N];
- void get_phi() {
- phi[1] = 1;
- int cnt = 0;
- for (int i = 2; i < N; i++) {
- if (!vis[i]) {
- vis[i] = i;
- prime[cnt++] = i;
- phi[i] = i - 1;
- }
- for (int j = 0; j < cnt; j++) {
- if (i * prime[j] > N) break;
- vis[i * prime[j]] = prime[j];
- int m = i * prime[j];
- if (i % prime[j] == 0) { // m = prime[i] * i * ````
- phi[m] = phi[i] * prime[j];
- break;
- }
- phi[m] = phi[i] * phi[prime[j]];
- }
- }
- }
- int main() {
- get_phi();
- sum[1] = 1;
- for (int i = 2; i <= N; i++)
- sum[i] = sum[i - 1] + phi[i];
- int n;
- cin >> n;
- if (n == 1) cout << "0" << endl;
- else {
- printf("%d\n", 2 * sum[n - 1] + 1);
- }
- return 0;
- }
欧拉筛法解决
后续写完更新
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。