赞
踩
目录
- #include <stdio.h>
-
- int main() {
- printf("Hello World\n");
- return 0;
- }
- #include <stdio.h>
-
- int main() {
- int x,y;
- scanf("%d%d",&x,&y);
- printf("%d",x+y);
- return 0;
- }
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <limits.h>
-
-
- int main() {
- int x;
- scanf("%d",&x);
- switch (x) {
- case 1:
- printf("%lu,%d,%d",sizeof(char),(-(unsigned char)~0)>>1,(unsigned char)~0>>1);
- break;
- case 2:
- printf("%lu,%u,%u",sizeof(unsigned char),(unsigned char)0,(unsigned char)~0);
- break;
- case 3:
- printf("%lu,%d,%d",sizeof(short),(-(unsigned short)~0)>>1,(unsigned short)~0>>1);
- break;
- case 4:
- printf("%lu,%u,%u",sizeof(unsigned short),(unsigned short)0,(unsigned short)~0);
- break;
- case 5:
- printf("%lu,%d,%d",sizeof(int),1<<(sizeof(int)*8-1),~(1<<(sizeof(int)*8-1)));
- break;
- case 6:
- printf("%lu,%u,%u",sizeof(unsigned int),(unsigned int)0,(unsigned int)~0);
- break;
- case 7:
- printf("%lu,%ld,%ld",sizeof(long),((long)1)<<(sizeof(long)*8-1),~(((long)1)<<(sizeof(long)*8-1)));
- break;
- case 8:
- printf("%lu,%lu,%lu",sizeof(unsigned long),(unsigned long)0,(unsigned long)~0);
- break;
- case 9:
- printf("%lu,%lld,%lld",sizeof(long long),((long long)1)<<(sizeof(long long)*8-1),~(((long long)1)<<(sizeof(long long)*8-1)));
- break;
- case 10:
- printf("%lu,%llu,%llu",sizeof(unsigned long long),(unsigned long long)0,(unsigned long long)~0);
- break;
- }
-
- return 0;
- }
- #include <stdio.h>
-
- int main() {
- int x,y,z;
- scanf("%d%d",&x,&y);
- z=x/2+y/2;
- printf("%d",z);
- return 0;
- }
- #include <stdio.h>
-
- int main() {
- int x;
- scanf("%d",&x);
- printf("%X,",x);
- printf("%o",x);
- //printf("%d",x);
- return 0;
- }
- #include <stdio.h>
-
- int main() {
- double x;
- scanf("%lf",&x);
- printf("%.6lf,",x);
- printf("%.2lf,",x);
- printf("%.8lf",x);
- return 0;
- }
- #include <stdio.h>
-
- int main() {
- int x,n,y;
- scanf("%d %d",&x,&n);
- y=x;
- while(y > 10) {
- y = y / 10;
- n--;
- }
- n--;
- while(n>0){
- printf("0");
- n--;
- }
- printf("%d",x);
- return 0;
- }
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #define PI 3.1415926
- #define EARTH_RADIUS 6371
- double radian(double d)
-
- {
-
- return d * PI / 180.0; //角度 = π / 180
-
- }
- double get_distance(double lat1, double lng1, double lat2, double lng2)
- {
-
- double radLat1 = radian(lat1);
-
- double radLat2 = radian(lat2);
-
- double a = radLat1 - radLat2;
-
- double b = radian(lng1) - radian(lng2);
-
- double dst = 2 * asin((sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2) )));
-
- dst = dst * EARTH_RADIUS;
-
- dst= round(dst * 10000) / 10000;
-
- return dst;
-
- }
- int main() {
- double lat1,lng1,lat2,lng2;
- scanf("%lf %lf\n%lf %lf",&lat1,&lng1,&lat2,&lng2);
- double dst = get_distance(lat1, lng1, lat2, lng2);
- printf("%0.4fkm\n",dst);
- return 0;
- }
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- int cold(int wp,int tep){
- double c;
- int res;
- c = 13.12+0.6215*tep-11.37*pow((double)wp,0.16)+0.3965*tep* pow((double)wp,0.16);
- res=(int)(c+0.5);
- return res;
- }
-
- int main() {
- int x,y;
- scanf("%d %d",&x,&y);
- int res;
- res= cold(x,y);
- printf("%d",res);
- return 0;
- }
- #include <stdio.h>
-
- void rgb_to_hsv(int r, int g, int b) {
- float R = r / 255.0f;
- float G = g / 255.0f;
- float B = b / 255.0f;
-
- float max = (R > G) ? ((R > B) ? R : B) : ((G > B) ? G : B);
- float min = (R < G) ? ((R < B) ? R : B) : ((G < B) ? G : B);
- float diff = max - min;
-
- float H = 0, S = 0, V = max * 100;
-
- if (max != min) {
- if (max == R) {
- H = 60 * ((G - B) / diff);
- } else if (max == G) {
- H = 60 * (2 + (B - R) / diff);
- } else if (max == B) {
- H = 60 * (4 + (R - G) / diff);
- }
- if (H < 0) {
- H += 360;
- }
- }
-
- if (max != 0) {
- S = diff / max * 100;
- }
-
- printf("%.4f,%.4f%%,%.4f%%\n", H, S, V);
- }
-
- int main() {
- int r, g, b;
- scanf("%d %d %d", &r, &g, &b);
- rgb_to_hsv(r, g, b);
- return 0;
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int is_false(int pill){
- if(pill==2||pill==3||pill==4||pill==5||pill==7)
- return 1;
- else return 0;
- }
- int main(){
- int num,n,reverse=0,pill,flag=1;
- scanf("%d",&num);
- n=num;
- while(n>0){
- pill = n%10;
- if(is_false(pill)) {
- flag=0;
- break;
- }
- else if(pill==9) pill=6;
- else if(pill==6) pill=9;
- reverse=reverse*10+pill;
- n/=10;
- }
- if(flag&&(reverse==num))
- printf("Yes");
- else printf("No");
-
- return 0;
-
- }
- #include <stdio.h>
-
- typedef unsigned long long ull;
-
- ull power_mod(ull a, ull b, ull m) {
- ull result = 1;
- while (b > 0) {
- if (b & 1) {
- result = (result * a) % m;
- }
- a = (a * a) % m;
- b >>= 1;
- }
- return result;
- }
-
- int main() {
- ull a, b, m;
- scanf("%llu %llu %llu", &a, &b, &m);
- printf("%llu\n", power_mod(a, b, m));
- return 0;
- }
- #include <stdio.h>
- #include <math.h>
-
- // 定义一个函数,用于计算最大公约数
- int gcd(int a, int b) {
- if (b == 0)
- return a;
- return gcd(b, a % b);
- }
-
- void convertToRatio(float num) {
- double precision = 0.0001; // 定义精度
- double decimal_part = num - (int)num; // 获取小数部分
- double tmp = decimal_part;
- int denominator = 1;
-
- // 通过连续乘法找到一个足够大的整数,使得浮点数可以被表示为两个整数的比率
- while (fabs(round(tmp) - tmp) > precision) {
- tmp = tmp * 10;
- denominator = denominator * 10;
- }
-
- int numerator = round(num * denominator); // 计算分子
- int divisor = gcd(numerator, denominator); // 计算最大公约数
-
- // 输出结果
- printf("%d/%d\n", numerator / divisor, denominator / divisor);
- }
-
- int main() {
- float num;
- scanf("%f",&num);
- convertToRatio(num);
- return 0;
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int sum_digital(int n){
- if (n<10) return n;
- else{
- return n%10 + sum_digital(n/10);
- }
- }
- int option(int n){
- if (n<=0)
- return 0;
- else{
- n -= sum_digital(n);
- return 1 + option(n);
- }
- }
- int main(){
- int res,n;
- scanf("%d",&n);
- if(n==0) res=1;
- else res= option(n);
- printf("%d",res);
- return 0;
-
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int combine(int n,int times,int *res){
- if (n==0&×==4)
- return 1;
- else{
- if(times==4||n<0)
- return 0;
-
- for(int i=0;i<10;i++){
- if (i>n) continue;
- *res+=combine(n-i,times+1,res);
- }
- return 0;
- }
- }
- int main(){
- int res,n;
- res=0;
- scanf("%d",&n);
- combine(n,0,&res);
- printf("%d",res);
-
- return 0;
-
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void output(int n,int direct){//1->+;0->-to1
- if(direct){
- for(int i=0;i<n;i++){
- printf("%d ",i);
- }
- }
- else {
- for (int i = n; i > 0; i--) {
- printf("%d ", i);
- }
- }
- }
- int main(){
- int n,j;
- scanf("%d",&n);
-
- for(j=0;j<n;j++) {
- output(j, 0);
- output(n - j, 1);
- printf("\n");
- }
-
- return 0;
-
- }
- #include <stdio.h>
-
- int main() {
- long long a, b, m;
- scanf("%lld %lld %lld", &a, &b, &m); // 从用户输入中读取三个整数
- long long result = ((a % m) * (b % m)) % m; // 计算a乘b后对m取模的结果
- printf("%lld\n", result); // 输出结果
- return 0;
- }
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- //using namespace std;
- void swap(int* a,int* b){
- int temp=(*a);
- (*a)=(*b);
- (*b)=temp;
- }
- int gcd(int m,int n){
- if(fabs(m)< fabs(n))
- swap(&m,&n);
- if(m%n==0) return n;
- else return (gcd(n,m%n));
- }
- void plus(int son_1,int mother_1,int son_2,int mother_2){
- int son,mother,m;
- son=son_1*mother_2+son_2*mother_1;
- mother=mother_1*mother_2;
- m=gcd(mother,son);
- son/=m;
- mother/=m;
- std::cout<<'('<<son_1<<'/'<<mother_1<<')'<<'+'<<'('<<son_2<<'/'<<mother_2<<')'<<'='<<son<<'/'<<mother<<std::endl;
- }
- void miner(int son_1,int mother_1,int son_2,int mother_2){
- int son,mother,m;
- son=son_1*mother_2-son_2*mother_1;
- mother=mother_1*mother_2;
- m=gcd(mother,son);
- son/=m;
- mother/=m;
- std::cout<<'('<<son_1<<'/'<<mother_1<<')'<<'-'<<'('<<son_2<<'/'<<mother_2<<')'<<'='<<son<<'/'<<mother<<std::endl;
- }
- void mul(int son_1,int mother_1,int son_2,int mother_2){
- int son,mother,m;
- son=son_1*son_2;
- mother=mother_1*mother_2;
- m=gcd(mother,son);
- son/=m;
- mother/=m;
- std::cout<<'('<<son_1<<'/'<<mother_1<<')'<<'*'<<'('<<son_2<<'/'<<mother_2<<')'<<'='<<son<<'/'<<mother<<std::endl;
- }
- void div(int son_1,int mother_1,int son_2,int mother_2){
- int son,mother,m;
- son=son_1*mother_2;
- mother=mother_1*son_2;
- m=gcd(mother,son);
- son/=m;
- mother/=m;
- std::cout<<'('<<son_1<<'/'<<mother_1<<')'<<'/'<<'('<<son_2<<'/'<<mother_2<<')'<<'='<<son<<'/'<<mother<<std::endl;
- }
- int main()
- {
- int son_1,mother_1,son_2,mother_2;
- std::cin>>son_1;
- std::cin.get();
- std::cin>>mother_1;
- std::cin.get();
- std::cin>>son_2;
- std::cin.get();
- std::cin>>mother_2;
- plus(son_1,mother_1,son_2,mother_2);
- miner(son_1,mother_1,son_2,mother_2);
- mul(son_1,mother_1,son_2,mother_2);
- div(son_1,mother_1,son_2,mother_2);
- //cout<<son_1<<' '<<mother_1<<' '<<son_2<<' '<<mother_2;
-
- return 0;
- }
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int T,i,j,m;
- int *a,*sum;
- cin>>T;
- a=new int[T]{0};
- sum=new int[T]{0};
- for(i=0;i<T;i++)
- {
- m=0;
- cin>>a[i];
- //scanf("%d",&a[i]);
- sum[i]=0;
- for(j=0;j<a[i];j++)
- {
- if(j%3==0||j%5==0)
- m=m+j;
- sum[i]=m;
- }
- }
- for(i=0;i<T;i++)
- cout<<sum[i]<<endl;
- //printf("%d\n",sum[i]);
- return 0;
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void output(int int_part,int float_part){
- if(float_part%10==0)
- float_part/=10;
- printf("%d.%d",int_part,float_part);
- }
- void sum(int n,int i,int *total_int,int *total_float){
- if (i<=n){
- int int_part=i;
- int float_part;
- if (i<9) float_part=10*(i+1);
- else if(i==99) float_part=10;
- else float_part=i+1;
-
- *total_int+=int_part;
- *total_float+=float_part;
- //check float_part<100
- if(*total_float>=100){
- *total_float%=100;
- (*total_int)++;
- }
- output(int_part,float_part);
- if(i==n) printf("=");
- else printf("+");
- sum(n,i+1,total_int,total_float);
- }
-
- }
- int main(){
- int total_int,total_float;
- short n;
- total_float=total_int=0;
- scanf("%hd",&n);
- // if(n!=99)
- sum(n,1,&total_int,&total_float);
- /* else{
- sum(n-1,1,&total_int,&total_float);
- total_int+=99;
- total_float+=10;
- if(total_float>=100) {
- total_float %= 100;
- total_int++;
- }
- }*/
- output(total_int,total_float);
- return 0;
-
- }
- #include <iostream>
- void div_fuc(int multiplicand,int multiplier, int res){
-
- while (multiplicand != 0) {
- std::cout << multiplicand << ' ' << multiplier << std::endl;
- if ((multiplicand % 2) != 0) res += multiplier;
- multiplicand = multiplicand >> 1;
- multiplier = multiplier << 1;
- }
-
- std::cout << res << std::endl;
-
- }
- int main(){
- int multiplicand,multiplier,res=0;
- std::cin >> multiplicand >> multiplier;
- div_fuc(multiplicand,multiplier,res);
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- int count_length(int x){
- int lens=0;
- while(x!=0){
- lens++;
- x/=10;
- }
- return lens;
- }
- int main(){
- int multiplicand,multiplier,res=0,multiplicand_digitalLens=0,multiplier_digitalLens=0,res_digitalLens=0;
- std::cin >> multiplicand >> multiplier;
- res = multiplicand*multiplier;
- multiplicand_digitalLens = count_length(multiplicand);
- multiplier_digitalLens = count_length(multiplier);
- res_digitalLens = count_length(res);
-
- std::cout << std::setw(res_digitalLens+1) << multiplicand << std::endl;
- std::cout << 'x' << std::setw(res_digitalLens) << multiplier << std::endl;
- std::cout << std::string(res_digitalLens+1,'-') << std::endl;
- int blank=-1;
- for(int i=multiplier_digitalLens-1;i>=0;i--){
- if (i == 0) std::cout << '+' << multiplicand*(multiplier%10) << std::endl;
- else
- std::cout << std::setw(res_digitalLens-blank) << multiplicand*(multiplier%10) << std::endl;
- multiplier /= 10;
- blank++;
- }
- std::cout << std::string(res_digitalLens+1,'-') << std::endl;
- std::cout << std::setw(res_digitalLens+1) << res << std::endl;
-
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- typedef long long ll;
-
- bool findTrue(ll N,ll num){
- if (N == 0) return true;
- else if( N%10 > num ) return false;
- else return (findTrue(N/10,N%10));
-
- }
- int main(){
- ll N,i;
- std::cin >> N;
- if (N<10) std::cout << N << std::endl;
- else {
- for (i = N; i > 0; i--) {
- if(findTrue(i/10,i%10)) break;
- }
- std::cout << i << std::endl;
- }
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
-
- int main(){
- int total_count=1,n;
- std::cin >> n;
- for(; n > 0; ){
- n-= total_count;
- total_count++;
- }
- total_count--;
- n+=total_count;
- std::cout << n;
-
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- typedef long long ll;
- int iter(ll N,ll i){
- ll j=i,tmp=0;
- while(j>0){
- tmp+=j;
- j--;
- if(tmp == N) return 1;
- else if (tmp > N) break;
- }
- return 0;
- }
- void solution(ll N,ll *res){
- for (int i = (N / 2) + 1; i >= 2; i--)
- (*res) += iter(N, i);
-
- }
-
- int main(){
- ll N,res=0;
- std::cin >> N;
- if (N<=2) {
- if (N==1) std::cout << 1;
- if (N==2) std::cout << 1;
- }
- else{
- solution(N,&res);
- std::cout << res+1;
- }
-
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
-
- int main(){
- long n,k,i=1,res=0;
- std::cin >> n >> k;
- for(;i<=n;i++){
- res+=k%i;
- }
- std::cout << res;
-
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- 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;
- std::cin >> N;
-
- std::cout << goodNumber(N,i);
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- int PourWater(int m_size,int n_size,int goal){
- int m_now=0,n_now=0,step1=0,step2=0;
- while(m_now!=goal&&n_now!=goal){
- if(m_now==0){
- m_now=m_size;//fill
-
- }
- else if(n_now==n_size){
- n_now=0; //pour out
-
- }
- else{
- int total = n_now + m_now>n_size?n_size-n_now:m_now;
- m_now-=total;
- n_now+=total;
-
- }
- step1++;
- }
-
- m_now=0,n_now=0;
- while(m_now!=goal&&n_now!=goal){
- if(n_now==0){
- n_now=n_size;//fill
-
- }
- else if(m_now==m_size){
- m_now=0; //pour out
-
- }
- else{
- int total = m_now + n_now>m_size?m_size-m_now:n_now;
- n_now-=total;
- m_now+=total;
- }
- step2++;
- }
- int step = step1>step2?step2:step1;
- return step;
- }
- int main(){
- int m,n,d;
- std::cin >> m >> n >> d;
- std::cout << PourWater(m,n,d);
-
- return 0;
- }
- #include <stdio.h>
-
- int main() {
- int n;
- scanf("%d", &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) {
- printf("%d\n", a * b * c);
- return 0;
- }
- }
- }
- printf("No solution\n");
- return 0;
- }
题解来自:NWPU-NOJ2023/26-阶乘倍数.cpp at main · Enifedefine/NWPU-NOJ2023 (github.com)
- #include <iostream>
- using namespace std;
- int main() {
- long long k;
- cin >> k;
- long long n = 1;
- for (long long i = 2 ; i * i <= k ; i ++){
- if (k % i == 0){
- long long count = 0;
- while (k % i == 0){
- k /= i;
- count ++;
- }
- n = max(n, count * i);
- }
- }
- if (k > 1){
- n = max(n, k);
- }
- cout << n << endl;
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- bool mod_2(long n){
- if(n%2==0) return true;
- else return false;
- }
- int main(){
- long n;
- std::cin >> n;
- while (n>1){
- std::cout << n << ' ';
- if(mod_2(n))
- n/=2;
- else n=3*n+1;
- }
- std::cout <<n;
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <stdarg.h>
-
- double avg(int n,...){
- va_list ap;
- int i;
- double sum=0.0;
- va_start(ap,n);
- for (i=0;i<n;i++){
- sum+= va_arg(ap,int);
- }
- va_end(ap);
- return (sum/n);
- }
- int main(){
- int a,b,c,d,e;
- std::cin >>a>>b>>c>>d>>e;
-
-
- std::cout <<std::fixed<<std::setprecision(4)<< (avg(2,a,b)-avg(3,c,d,e));
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <stdarg.h>
-
- int sum(int first,...){
- va_list ap;
- int tmp,sum=0;
- va_start(ap,first);
- tmp= first;
- sum+=tmp;
- while(tmp>0) {
- tmp= va_arg(ap,int);
- sum += tmp;
- }
-
- va_end(ap);
- return sum;
- }
- int main(){
- int a,b,c,d,e,f;
- std::cin >>a>>b>>c>>d>>e>>f;
-
-
- std::cout << (sum(a,b,0)-sum(c,d,e,f,0));
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- int PA(int n){
- if(n==0) return 0;
- else if(n==1) return 1;
- else return 2* PA(n-1)+PA(n-2);
- }
- int main(){
- int n;
- std::cin >> n;
-
-
- std::cout << PA(n);
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- void print(int n){
- int i=0,tmp=n;
- while(tmp>0){
- tmp>>=1;
- i++;
- }
- i--;
- tmp=(int)pow(2,i);
- int top=tmp;
-
- for(;tmp>0;tmp>>=1,--i){
- if((n&tmp)==tmp){
- if( i == 1 ) {
- if(tmp!=top)std::cout << '+';
- std::cout << "2";
- }
- else if(i==0){
- if(tmp!=top)std::cout << '+';
- std::cout << "2(";
- std::cout << i;
- std::cout << ')';
- }
- else{
- if(tmp!=top)std::cout << '+';
- std::cout << "2(";
- print(i);
- std::cout << ')';
-
- }
-
- }
- }
- }
-
- int main(){
- int n;
- std::cin >> n;
- print(n);
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- inline bool is_prime(int num){
- if (num <= 3)
- {
- return num > 1;
- }
- // 不在6的倍数两侧的一定不是质数
- if (num % 6 != 1 && num % 6 != 5)
- {
- return false;
- }
- int sqr = (int)sqrt(num);
- for (int i = 5; i <= sqr; i += 6)
- {
- if (num % i == 0 || num % (i + 2) == 0)
- {
- return false;
- }
- }
- return true;
- }
- inline int NumOfPrime(int bottom,int top){
- int i=bottom,nums_ofPrime=0;
- for(;i<=top;i++){
- if(is_prime(i)) {
- nums_ofPrime++;
- }
- }
- return nums_ofPrime;
- }
- int main(){
- int bottom,top;
- std::cin >> bottom >> top;
- std::cout << NumOfPrime(bottom,top);
- return 0;
- }
题解来自:NWPU-NOJ2023/40-光线追踪.cpp at main · Enifedefine/NWPU-NOJ2023 (github.com)
- #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>
- 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;
- std::cin >> n;
-
- while(n>=2){
- if(HarshadNumber(n)!=0){
- n = HarshadNumber(n);
- i++;
- }
- else break;
- }
- std::cout << i << std::endl;
- return 0;
- }
提交上去一直一直超时,所以我想了个笨办法:把40000个结果写入一个txt文件:p
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <fstream>
- inline int gcd(int a,int b){
- if(a%b==0) return b;
- else return gcd(b,a%b);
- }
- bool IsSeen(int a,int b){
-
- if(gcd(a,b)==1) return true;
- else return false;
- }
-
- int main() {
- int nums=0,x=40000;
- std::cin >> x; //x默认是40000
- std::ofstream file;
- file.open("nums.txt");
- file << 1 ;
- for(int i=1;i<x;i++) {
- for (int j = 1; j < i; j++) {
- if (IsSeen(i > j ? i : j, i > j ? j : i)) {
- nums++;
- //std::cout << i <<' '<< j <<std::endl;
- }
-
- }
- file << " ," << nums*2 + 3;
- std::cout << nums * 2 + 3 << std::endl;
- }
- return 0;
- }
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <fstream>
- int main() {
- int n;
- int nums[40000]= {/*在nums.txt文件中的数字*/}
- std::cin >> n;
- std::cout << nums[n-1] << std::endl;
-
- return 0;
- }
一种很好的办法,简洁地求出欧拉函数:
- #include <stdio.h>
- #include <stdlib.h>
-
- //找到小于n与n互质的数的个数即可(欧拉函数)
- //https://www.luogu.com.cn/problem/solution/P2158
- int main()
- {
- int n,ans,p[50000],i,j;
- scanf("%d",&n);
- for(i=1;i<=n;++i)
- {
- p[i]=i;//赋初值(假定所有数都互质)
- }
-
- for(i=2;i<=n;++i)
- {
- if(p[i]==i)//如果i是质数
- {
- for(j=i;j<=n;j+=i)
- {
- //此处质数i直接带入欧拉函数进行计算
- //phi(j) = j * (1 - 1/p)
- p[j]=p[j]*(i-1)/i;
- }
- }
- }
-
- for(i=1;i<n;++i)
- {
- ans+=p[i];
- }
- printf("%d\n",(n==1)?0:ans<<1|1);//n=1时候特判
- 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;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。