LightOj 1278 - Sum of Consecutive Integers
Problem Link: LightOj 1278 - Sum of Consecutive Integers
// Accepted #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <string> #include <vector> #include <cmath> #include <cctype> #include <sstream> #include <set> #include <list> #include <stack> #include <queue> #include <algorithm> #define sf scanf #define pf printf #define sfint scanf ("%d %d",&a,&b) #define sfl scanf ("%ld %ld",&a,&b) #define sfll scanf ("%lld %lld",&a,&b) #define sfd scanf ("%lf %lf",&a,&b) #define sff scanf ("%f %f",&a,&b) #define lp1(i,n) for(i=0;i<n;i++) #define lp2(i,n) for(i=1;i<=n;i++) #define LL long long #define L long #define mem(c,v) memset(c,v,sizeof(c)) #define ui unsigned int #define cp(a) cout<<" "<<a<<" "<<endl #define ull unsigned long long int #define nl puts("") #define sq(x) ((x)*(x)) #define mx7 20000100 #define mx6 1500000 #define mx5 10000005 #define inf 1<<30 //infinity value #define eps 1e-9 #define mx (65540) #define mod 1000000007 #define pb push_back #define pi acos(-1.0) #define sz size() #define gc getchar () using namespace std; int setbit(int n, int pos){n=n|(1<<pos); return n;} bool checkbit(int n, int pos){n=n&(1<<pos); return n;} bool flag[mx5]; int prm[(mx5/2)+1],plen=0; void seieve() { mem(flag,false); flag[0]=flag[1]=true; int qrt=(int)sqrt(double(mx5)); for(int i=4;i<=mx5;i+=2)flag[i]=true; for(int i=3;i<=qrt;i+=2) { if(!flag[i]) { for(LL j=i*i;j<=mx5;j+=i) { flag[j]=true; } } } for(int i=2;i<=mx5;i++) { if(!flag[i]) { prm[plen++]=i; } } } LL smi(LL n) { LL m=1; for(int i=0;i<plen and sq(prm[i])<=n;i++) { if(!(n%prm[i])) { int s=1; while(!(n%prm[i])) { s+=1; n/=prm[i]; if(n==1 or n==0) break; } if(prm[i]&1) { m*=s; } } } if(n>1 and n&1) { m=m<<1; } m--; return m; } int main() { seieve(); int t,tc=0; sf("%d",&t); while(t--) { LL n; sf("%lld",&n); pf("Case %d: %lld\n",++tc,smi(n)); } return 0; } //Critical TestCase:: //5 //80248409469439 //43660801947259 //75303949780302 //12764781726378 //99999999999973
Accepted Output |
Comments
Post a Comment