#include<cstdio> #include<cmath> using namespace std; int phi(int n) { int res=n; for (int i=2;i*i<=n;i++) { if (n%i==0) { while (n%i==0) n/=i; res-=res/i; } } if (n>1) res-=res/n; return res; } int main () { int n; while (scanf("%d",&n)==1) { if (n==0) return 0; if (n==1) printf("0\n"); else printf("%d\n",phi(n)); } return 0; }
Friday, August 12, 2016
Published August 12, 2016 by Sourav Chowdhury with 0 comment
Wednesday, August 10, 2016
Published August 10, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cmath> using namespace std; int main() { int t,s,x; scanf("%d%d%d",&t,&s,&x); if (x>=t &&( (x-t)%s==0 || (x-t-1!=0 && (x-t-1)%s==0))) printf("YES\n"); else printf("NO\n"); return 0; }
Published August 10, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cstring> using namespace std; int main() { int n,l,r,u,d; l=r=u=d=0; scanf("%d",&n); getchar(); char s[11]; scanf("%s",s); for (int i=0;i<n;i++){ int a=s[i]-'0'; if (a==1 || a==4||a==7||a==0) l=1; if (a==3 || a==6||a==9||a==0) r=1; if (a==1 || a==2||a==3) u=1; if (a==7 || a==0||a==9) d=1; } if (l && r && u && d) printf("YES\n"); else printf("NO\n"); return 0; }
Published August 10, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cstring> using namespace std; int main() { char s[100005]; gets(s); printf("%s",s); for (int i=strlen(s)-1;i>-1;i--) printf("%c",s[i]); printf("\n"); return 0; }
Published August 10, 2016 by Sourav Chowdhury with 2 comments
#include<cstdio> using namespace std; int main() { int n; scanf("%d",&n); int a[n]; for (int i=0;i<n;i++) scanf("%d",&a[i]); int rest=0; int p=0; for (int i=0;i<n;i++) { if (a[i]==0){ rest++; p=0; } else if (!p){ p=a[i]; } else if (p==3){ p=a[i]; } else if(p==2 && a[i]!=2 ){ p=1; } else if(p==2 && a[i]==2 ){ p=0; rest++; } else if(p==1 && a[i]!=1 ){ p=2; } else if(p==1 && a[i]==1 ){ p=0; rest++; } } printf("%d\n",rest); return 0; }
Tuesday, August 9, 2016
Published August 09, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> using namespace std; int main() { int n; scanf("%d",&n); int a[n]; for (int i=0;i<n;i++){ scanf("%d",&a[i]); } int max=1,cur=1; for (int i=1;i<n;i++){ if (a[i]>a[i-1]){ cur++; } else{ if (max<cur) max=cur; cur=1; } } if (max<cur) max=cur; printf("%d\n",max); return 0; }
Monday, August 8, 2016
Published August 08, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<string.h> using namespace std; typedef long long unsigned int llu; int main() { int n,k; while (scanf("%d%d",&n,&k)!=EOF) { int c[n+1]; int d[k]; bool cap[n+1]; memset(cap,false,sizeof(cap)); llu sum=0,ans=0; for (int i=1;i<=n;i++) { scanf("%d",&c[i]); sum+=c[i]; } for (int i=0;i<k;i++) { scanf("%d",&d[i]); cap[d[i]]=true; } for (int i=0;i<k;i++) { ans+=c[d[i]]*(sum-c[d[i]]); sum-=c[d[i]]; } for (int i=1;i<n;i++) if (!cap[i] && !cap[i+1]) ans+=c[i]*c[i+1]; if (!cap[1] && !cap[n]) ans+=c[1]*c[n]; printf("%llu\n",ans); } return 0; }
Subscribe to:
Posts (Atom)