CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home  » Codechef Campus Snackdown » Rational Numbers » All Submissions » code4life [136801]
0
Your rating: None

CodeChef submission 136801 (C++ 4.0.0-8)

CodeChef submission 136801 (C++ 4.0.0-8) plaintext list. Status: WA, problem SNCK04, contest SNACKDWN. By code4life (code4life), 2009-11-21 23:58:57.
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <stack>
  7. #include <bitset>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <numeric>
  11. #include <utility>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <cstdio>
  16. #include <cmath>
  17. #include <cstdlib>
  18. #include <ctime>
  19. #include<string>
  20. #define MAX 1000001
  21. #define eps 1e-6
  22. using namespace std;
  23. string i2s(int n)
  24. { stringstream ss;
  25. ss<<n;
  26. return ss.str();
  27. }
  28. int s2i(string h)
  29. { stringstream ss;
  30. ss<<h;
  31. int n;
  32. ss>>n;
  33. return n;
  34. }
  35. long long array[1000000];long long array1[1000000];
  36. int main()
  37. { vector<int> prime;prime.clear();prime.push_back(2);int count=0;
  38. for(int i=3;i<=1000;i=i+2)
  39. { set<int> s;s.clear();
  40. double r=sqrt(i);
  41. for(int j=1;j<=floor(r);j++)
  42. { if(i%j==0)
  43. { s.insert(j);
  44. s.insert(i/j);
  45. }
  46. }
  47. if(s.size()==2)
  48. { prime.push_back(i);
  49. count++;
  50. }
  51. }
  52. memset(array,0,sizeof(array));memset(array1,0,sizeof(array1));
  53. array[0]=0;array[1]=1;array1[0]=0;array1[1]=1;
  54. for(int i=3;i<=1000000;i++)
  55. { int p=i;int l=(int)sqrt(i);bool flag=false;
  56. for(int j=0;j<prime.size() && prime[j]<=l;j++)
  57. { if(p%prime[j]==0)
  58. { array[i-1]=((array[(p/prime[j])-1]*i)/(p/prime[j]));flag=true;
  59. break;
  60. }
  61. }
  62. if(!flag)
  63. { // case of prime value
  64. array[i-1]=(i-1);
  65. }
  66. array1[i-1]=array1[i-2]+(array[i-1]);
  67. }
  68. int t;scanf("%d",&t);
  69. while(t--)
  70. { int num;scanf("%d",&num);//cout<<array[num-1]<<endl;
  71. cout<<array[num-1]<<endl;
  72. }
  73. system("pause");
  74. }


Comments

  • Login or Register to post a comment.

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com