A 判断不同字母的个数为偶数还是奇数
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int i,j,k,n,num[500]; memset(num,0,sizeof(num)); char str[201]; gets(str); k = strlen(str); for(i = 0 ; i < k ; i++) num[str[i]]++; int count = 0; for(i = 0 ; i < 500 ; i++) if(num[i]) count++; if(count%2==0) printf("CHAT WITH HER!\n"); else printf("IGNORE HIM!"); return 0; }
B题
求一个数的因数的个数公式
对一个数X分解质因子得 X = p1a1 *
p2a2 * p3a3 * ... pkak ,X的因子数为 (a1 + 1)*(a2 + 1)*(a3 + 1)*...*(ak + 1);
写的乱七八糟的
#include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; __int64 s,ss; int num[1000001],dis[10000],pr[100000],pd[100000]; int main() { int a,b,c,i,j,k; cin>>a>>b>>c; for(i = 2; i <= 10000 ; i++) { if(!pr[i]) { for(j = i+i ; j <= 10000 ; j+=i) if(pr[j]) pr[j] = 1; } } int g = 0; for(i =2; i <= 10000 ; i++) if(!pr[i]) pd[g++] = i; s = 0; for(i = 1; i <= a ; i++) for(j = 1; j <= b ; j++) for(k = 1; k <= c ; k++) { ss = i*j*k; __int64 xx = ss; if(!num[ss]) { int y = 0,kk =0 ,tt = 1; while(xx) { if(xx%pd[y]==0) { kk++; xx = xx/pd[y]; } else { tt = tt*(kk+1); y++; kk = 0; } if(xx==1) break; } if(kk) tt = tt*(kk+1); num[ss] = tt; } s+=num[ss]; s = s%1073741824; } printf("%I64d\n",s); return 0; }
C题 直接枚举 忘用——int64了
View Code
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #define INF 0xfffffff 6 using namespace std; 7 __int64 gcd(__int64 a,__int64 b) 8 { 9 return b==0?a:gcd(b,a%b); 10 } 11 int main() 12 { 13 int i,j,k,n; 14 __int64 s = 1,max = 0; 15 cin>>n; 16 if(n>200) 17 { 18 for(i = n-200 ; i <= n ; i++) 19 for(j = i ; j <= n ; j++) 20 for(k = j ; k <= n ; k++) 21 { 22 s = i/(gcd(i,j))*j; 23 s = s/(gcd(s,k))*k; 24 if(s>max) 25 max = s; 26 } 27 } 28 else 29 { 30 for(i = 1 ; i <= n ; i++) 31 for(j = i ; j <= n ; j++) 32 for(k = j ; k <= n ; k++) 33 { 34 s = i/(gcd(i,j))*j; 35 s = s/(gcd(s,k))*k; 36 if(s>max) 37 max = s; 38 } 39 } 40 printf("%I64d\n",max); 41 return 0; 42 }